Skip to content

Commit 49a16be

Browse files
authored
Merge pull request #4 from grhaonan/master
Adding create chat completion sample code to readme
2 parents 8b969ed + 7aa85c9 commit 49a16be

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,25 @@ Examples:
170170
```
171171
(For this to work you need to use `OpenAIServiceStreamedFactory` from `openai-scala-client-stream` lib)
172172

173+
- Create chat completion
174+
175+
```scala
176+
val createChatCompletionSettings = CreateChatCompletionSettings(
177+
model = ModelId.gpt_3_5_turbo_0301
178+
)
179+
180+
val messages: Seq[MessageSpec] = Seq(
181+
MessageSpec(role = ChatRole.System, content = "You are a helpful assistant."),
182+
MessageSpec(role = ChatRole.User, content = "Who won the world series in 2020?"),
183+
MessageSpec(role = ChatRole.Assistant, content = "The Los Angeles Dodgers won the World Series in 2020."),
184+
MessageSpec(role = ChatRole.User, content = "Where was it played"),
185+
)
186+
187+
service.createChatCompletion(messages = messages, settings = createChatCompletionSettings).map { chatCompletion =>
188+
println(chatCompletion.choices.head.message.content)
189+
}
190+
```
191+
173192
## FAQ 🤔
174193

175194
1. _Wen Scala 3?_

0 commit comments

Comments
 (0)