Skip to content

Commit

Permalink
#131: Update test files
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger12 committed Feb 12, 2024
1 parent 6ab5bb3 commit 8aeeb00
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 39 deletions.
49 changes: 49 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,52 @@ const docTemplate = `{
}
}
},
"bedrock.Config": {
"type": "object",
"required": [
"awsRegion",
"baseUrl",
"chatEndpoint",
"model"
],
"properties": {
"awsRegion": {
"type": "string"
},
"baseUrl": {
"type": "string"
},
"chatEndpoint": {
"type": "string"
},
"defaultParams": {
"$ref": "#/definitions/bedrock.Params"
},
"model": {
"type": "string"
}
}
},
"bedrock.Params": {
"type": "object",
"properties": {
"max_tokens": {
"type": "integer"
},
"stop": {
"type": "array",
"items": {
"type": "string"
}
},
"temperature": {
"type": "number"
},
"top_p": {
"type": "number"
}
}
},
"clients.ClientConfig": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -517,6 +563,9 @@ const docTemplate = `{
"azureopenai": {
"$ref": "#/definitions/azureopenai.Config"
},
"bedrock": {
"$ref": "#/definitions/bedrock.Config"
},
"client": {
"$ref": "#/definitions/clients.ClientConfig"
},
Expand Down
49 changes: 49 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,52 @@
}
}
},
"bedrock.Config": {
"type": "object",
"required": [
"awsRegion",
"baseUrl",
"chatEndpoint",
"model"
],
"properties": {
"awsRegion": {
"type": "string"
},
"baseUrl": {
"type": "string"
},
"chatEndpoint": {
"type": "string"
},
"defaultParams": {
"$ref": "#/definitions/bedrock.Params"
},
"model": {
"type": "string"
}
}
},
"bedrock.Params": {
"type": "object",
"properties": {
"max_tokens": {
"type": "integer"
},
"stop": {
"type": "array",
"items": {
"type": "string"
}
},
"temperature": {
"type": "number"
},
"top_p": {
"type": "number"
}
}
},
"clients.ClientConfig": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -514,6 +560,9 @@
"azureopenai": {
"$ref": "#/definitions/azureopenai.Config"
},
"bedrock": {
"$ref": "#/definitions/bedrock.Config"
},
"client": {
"$ref": "#/definitions/clients.ClientConfig"
},
Expand Down
33 changes: 33 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,37 @@ definitions:
user:
type: string
type: object
bedrock.Config:
properties:
awsRegion:
type: string
baseUrl:
type: string
chatEndpoint:
type: string
defaultParams:
$ref: '#/definitions/bedrock.Params'
model:
type: string
required:
- awsRegion
- baseUrl
- chatEndpoint
- model
type: object
bedrock.Params:
properties:
max_tokens:
type: integer
stop:
items:
type: string
type: array
temperature:
type: number
top_p:
type: number
type: object
clients.ClientConfig:
properties:
timeout:
Expand Down Expand Up @@ -262,6 +293,8 @@ definitions:
$ref: '#/definitions/anthropic.Config'
azureopenai:
$ref: '#/definitions/azureopenai.Config'
bedrock:
$ref: '#/definitions/bedrock.Config'
client:
$ref: '#/definitions/clients.ClientConfig'
cohere:
Expand Down
6 changes: 1 addition & 5 deletions pkg/providers/bedrock/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import (
"glide/pkg/telemetry"
)

// TODO: Explore resource pooling
// TODO: Optimize Type use
// TODO: Explore Hertz TLS & resource pooling

const (
providerName = "openai"
providerName = "bedrock"
)

// ErrEmptyResponse is returned when the OpenAI API returns an empty response.
Expand Down
11 changes: 5 additions & 6 deletions pkg/providers/bedrock/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import (
)

func TestBedrockClient_ChatRequest(t *testing.T) {
// OpenAI Chat API: https://platform.openai.com/docs/api-reference/chat/create
openAIMock := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
bedrockMock := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rawPayload, _ := io.ReadAll(r.Body)

var data interface{}
Expand All @@ -44,20 +43,20 @@ func TestBedrockClient_ChatRequest(t *testing.T) {
}
})

openAIServer := httptest.NewServer(openAIMock)
defer openAIServer.Close()
BedrockServer := httptest.NewServer(bedrockMock)
defer BedrockServer.Close()

ctx := context.Background()
providerCfg := DefaultConfig()
clientCfg := clients.DefaultClientConfig()

providerCfg.BaseURL = openAIServer.URL
providerCfg.BaseURL = BedrockServer.URL

client, err := NewClient(providerCfg, clientCfg, telemetry.NewTelemetryMock())
require.NoError(t, err)

request := schemas.UnifiedChatRequest{Message: schemas.ChatMessage{
Role: "human",
Role: "user",
Content: "What's the biggest animal?",
}}

Expand Down
9 changes: 3 additions & 6 deletions pkg/providers/bedrock/testdata/chat.req.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
"model": "gpt-3.5-turbo",
"model": "amazon.titan-text-express-v1",
"messages": [
{
"role": "human",
"role": "user",
"content": "What's the biggest animal?"
}
],
"temperature": 0.8,
"top_p": 1,
"max_tokens": 100,
"n": 1,
"user": null,
"seed": null
"max_tokens": 100
}
22 changes: 1 addition & 21 deletions pkg/providers/bedrock/testdata/chat.success.json
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-3.5-turbo-0613",
"system_fingerprint": "fp_44709d6fcb",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?"
},
"logprobs": null,
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}
{"provider":"bedrock","model":"amazon.titan-text-express-v1","modelResponse":{"responseId":{"system_fingerprint":""},"message":{"role":"assistant","content":"\nThe largest animal in the world is the blue whale, which can reach lengths of over 100 feet and weigh as much as 200 tons."},"tokenCount":{"promptTokens":34,"responseTokens":34,"totalTokens":34}}}
2 changes: 1 addition & 1 deletion pkg/providers/openai/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestOpenAIClient_ChatRequest(t *testing.T) {
require.NoError(t, err)

request := schemas.UnifiedChatRequest{Message: schemas.ChatMessage{
Role: "human",
Role: "user",
Content: "What's the biggest animal?",
}}

Expand Down

0 comments on commit 8aeeb00

Please sign in to comment.