Skip to content

Commit

Permalink
Merge pull request #177 from softwaremill/v2-migration
Browse files Browse the repository at this point in the history
Added support for v2 changes
  • Loading branch information
Pask423 authored May 21, 2024
2 parents e390973 + 07d3797 commit 3e3119e
Show file tree
Hide file tree
Showing 34 changed files with 1,508 additions and 714 deletions.
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sttp is a family of Scala HTTP-related projects, and currently includes:

* [sttp client](https://github.com/softwaremill/sttp): The Scala HTTP client you always wanted!
* [sttp tapir](https://github.com/softwaremill/tapir): Typed API descRiptions
* sttp openai: this project. Scala client wrapper for OpenAI (and OpenAI-compatible) API. Use the power of ChatGPT inside your code!
* sttp openai: this project. Non-official Scala client wrapper for OpenAI (and OpenAI-compatible) API. Use the power of ChatGPT inside your code!

## Intro
Sttp-openai uses sttp client to describe requests and responses used in OpenAI (and OpenAI-compatible) endpoints.
Expand Down Expand Up @@ -39,8 +39,11 @@ import sttp.openai.requests.completions.chat.ChatRequestBody.{ChatBody, ChatComp
import sttp.openai.requests.completions.chat.message._

object Main extends App {
// Read your API secret-key from env variables
private val apiKey = System.getenv("openai-key")

// Create an instance of OpenAISyncClient providing your API secret-key
val openAI: OpenAISyncClient = OpenAISyncClient("your-secret-key")
val openAI: OpenAISyncClient = OpenAISyncClient(apiKey)

// Create body of Chat Completions Request
val bodyMessages: Seq[Message] = Seq(
Expand Down Expand Up @@ -96,7 +99,6 @@ object Main extends App {
content = Content.TextContent("Hello!"),
)
)


val chatRequestBody: ChatBody = ChatBody(
// assuming one has already executed `ollama pull mistral` in console
Expand Down Expand Up @@ -144,7 +146,11 @@ import sttp.openai.requests.completions.chat.message._

object Main extends IOApp {
override def run(args: List[String]): IO[ExitCode] = {
val openAI: OpenAI = new OpenAI("your-secret-key", uri"https://api.groq.com/openai/v1")
// Read your API secret-key from env variables
val apiKey = System.getenv("openai-key")

// Create an instance of OpenAISyncClient providing your API secret-key
val openAI: OpenAI = new OpenAI(apiKey, uri"https://api.groq.com/openai/v1")

val bodyMessages: Seq[Message] = Seq(
Message.UserMessage(
Expand All @@ -156,6 +162,7 @@ object Main extends IOApp {
model = ChatCompletionModel.CustomChatCompletionModel("gemma-7b-it"),
messages = bodyMessages
)

HttpClientCatsBackend.resource[IO]().use { backend =>
val response: IO[Either[OpenAIException, ChatResponse]] =
openAI
Expand Down Expand Up @@ -212,7 +219,11 @@ import sttp.openai.requests.completions.chat.message._

object Main extends IOApp {
override def run(args: List[String]): IO[ExitCode] = {
val openAI: OpenAI = new OpenAI("your-secret-key")
// Read your API secret-key from env variables
val apiKey = System.getenv("openai-key")

// Create an instance of OpenAISyncClient providing your API secret-key
val openAI: OpenAI = new OpenAI(apiKey)

val bodyMessages: Seq[Message] = Seq(
Message.UserMessage(
Expand All @@ -224,6 +235,7 @@ object Main extends IOApp {
model = ChatCompletionModel.GPT35Turbo,
messages = bodyMessages
)

HttpClientCatsBackend.resource[IO]().use { backend =>
val response: IO[Either[OpenAIException, ChatResponse]] =
openAI
Expand Down Expand Up @@ -282,7 +294,11 @@ import sttp.openai.requests.completions.chat.message._

object Main extends IOApp {
override def run(args: List[String]): IO[ExitCode] = {
val openAI: OpenAI = new OpenAI("your-secret-key")
// Read your API secret-key from env variables
val apiKey = System.getenv("openai-key")

// Create an instance of OpenAISyncClient providing your API secret-key
val openAI: OpenAI = new OpenAI(apiKey)

val bodyMessages: Seq[Message] = Seq(
Message.UserMessage(
Expand Down
Loading

0 comments on commit 3e3119e

Please sign in to comment.