Skip to content

Commit

Permalink
#60: anthropic client (#89)
Browse files Browse the repository at this point in the history
* #60: Add Anthropic provider

* Update chat provider response schema, replace responseID

* #60: Fix field naming conventions in language.go and chat.go

* #60: reduce complexity of toModel func and lint

* #60: add test

* #60: lint

---------

Co-authored-by: Max <[email protected]>
  • Loading branch information
mkrueger12 and mkrueger12 authored Jan 19, 2024
1 parent 5790d32 commit fa786ee
Show file tree
Hide file tree
Showing 16 changed files with 641 additions and 47 deletions.
54 changes: 54 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,57 @@ const docTemplate = `{
}
},
"definitions": {
"anthropic.Config": {
"type": "object",
"required": [
"baseUrl",
"chatEndpoint",
"model"
],
"properties": {
"baseUrl": {
"type": "string"
},
"chatEndpoint": {
"type": "string"
},
"defaultParams": {
"$ref": "#/definitions/anthropic.Params"
},
"model": {
"type": "string"
}
}
},
"anthropic.Params": {
"type": "object",
"properties": {
"max_tokens": {
"type": "integer"
},
"metadata": {
"type": "string"
},
"stop": {
"type": "array",
"items": {
"type": "string"
}
},
"system": {
"type": "string"
},
"temperature": {
"type": "number"
},
"top_k": {
"type": "integer"
},
"top_p": {
"type": "number"
}
}
},
"azureopenai.Config": {
"type": "object",
"required": [
Expand Down Expand Up @@ -458,6 +509,9 @@ const docTemplate = `{
"id"
],
"properties": {
"anthropic": {
"$ref": "#/definitions/anthropic.Config"
},
"azureopenai": {
"$ref": "#/definitions/azureopenai.Config"
},
Expand Down
54 changes: 54 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,57 @@
}
},
"definitions": {
"anthropic.Config": {
"type": "object",
"required": [
"baseUrl",
"chatEndpoint",
"model"
],
"properties": {
"baseUrl": {
"type": "string"
},
"chatEndpoint": {
"type": "string"
},
"defaultParams": {
"$ref": "#/definitions/anthropic.Params"
},
"model": {
"type": "string"
}
}
},
"anthropic.Params": {
"type": "object",
"properties": {
"max_tokens": {
"type": "integer"
},
"metadata": {
"type": "string"
},
"stop": {
"type": "array",
"items": {
"type": "string"
}
},
"system": {
"type": "string"
},
"temperature": {
"type": "number"
},
"top_k": {
"type": "integer"
},
"top_p": {
"type": "number"
}
}
},
"azureopenai.Config": {
"type": "object",
"required": [
Expand Down Expand Up @@ -455,6 +506,9 @@
"id"
],
"properties": {
"anthropic": {
"$ref": "#/definitions/anthropic.Config"
},
"azureopenai": {
"$ref": "#/definitions/azureopenai.Config"
},
Expand Down
36 changes: 36 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
basePath: /
definitions:
anthropic.Config:
properties:
baseUrl:
type: string
chatEndpoint:
type: string
defaultParams:
$ref: '#/definitions/anthropic.Params'
model:
type: string
required:
- baseUrl
- chatEndpoint
- model
type: object
anthropic.Params:
properties:
max_tokens:
type: integer
metadata:
type: string
stop:
items:
type: string
type: array
system:
type: string
temperature:
type: number
top_k:
type: integer
top_p:
type: number
type: object
azureopenai.Config:
properties:
apiVersion:
Expand Down Expand Up @@ -224,6 +258,8 @@ definitions:
type: object
providers.LangModelConfig:
properties:
anthropic:
$ref: '#/definitions/anthropic.Config'
azureopenai:
$ref: '#/definitions/azureopenai.Config'
client:
Expand Down
26 changes: 21 additions & 5 deletions pkg/api/schemas/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type UnifiedChatResponse struct {
// ProviderResponse is the unified response from the provider.

type ProviderResponse struct {
ResponseID map[string]string `json:"responseId,omitempty"`
SystemID map[string]string `json:"responseId,omitempty"`
Message ChatMessage `json:"message"`
TokenCount TokenCount `json:"tokenCount"`
}
Expand All @@ -53,7 +53,7 @@ type ChatMessage struct {
Name string `json:"name,omitempty"`
}

// OpenAI Chat Response
// OpenAI Chat Response (also used by Azure OpenAI and OctoML)
// TODO: Should this live here?
type OpenAIChatCompletion struct {
ID string `json:"id"`
Expand Down Expand Up @@ -113,7 +113,7 @@ type Citation struct {
Start int `json:"start"`
End int `json:"end"`
Text string `json:"text"`
DocumentID []string `json:"documentId"`
DocumentID []string `json:"document_id"`
}

type Documents struct {
Expand All @@ -123,11 +123,11 @@ type Documents struct {

type SearchQuery struct {
Text string `json:"text"`
GenerationID string `json:"generationId"`
GenerationID string `json:"generation_id"`
}

type SearchResults struct {
SearchQuery []SearchQueryObject `json:"searchQuery"`
SearchQuery []SearchQueryObject `json:"search_query"`
Connectors []ConnectorsResponse `json:"connectors"`
DocumentID []string `json:"documentId"`
}
Expand All @@ -143,3 +143,19 @@ type ConnectorsResponse struct {
ContOnFail string `json:"continue_on_failure"`
Options map[string]string `json:"options"`
}

// Anthropic Chat Response
type AnthropicChatCompletion struct {
ID string `json:"id"`
Type string `json:"type"`
Model string `json:"model"`
Role string `json:"role"`
Content []Content `json:"content"`
StopReason string `json:"stop_reason"`
StopSequence string `json:"stop_sequence"`
}

type Content struct {
Type string `json:"type"`
Text string `json:"text"`
}
Loading

0 comments on commit fa786ee

Please sign in to comment.