File tree Expand file tree Collapse file tree 3 files changed +32
-13
lines changed
Expand file tree Collapse file tree 3 files changed +32
-13
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ func getOllamaConfig() base.ProviderConfig {
3333 return base.ProviderConfig {
3434 BaseURL : "" ,
3535 ChatCompletions : "/api/chat" ,
36- Embeddings : "/api/embeddings " ,
36+ Embeddings : "/api/embed " ,
3737 }
3838}
3939
Original file line number Diff line number Diff line change @@ -22,8 +22,8 @@ func (p *OllamaProvider) CreateEmbeddings(request *types.EmbeddingRequest) (*typ
2222 headers := p .GetRequestHeaders ()
2323
2424 ollamaRequest := & EmbeddingRequest {
25- Model : request .Model ,
26- Prompt : request .ParseInputString () ,
25+ Model : request .Model ,
26+ Input : request .Input ,
2727 }
2828
2929 // 创建请求
@@ -50,18 +50,32 @@ func (p *OllamaProvider) CreateEmbeddings(request *types.EmbeddingRequest) (*typ
5050 }
5151 }
5252
53- response := & types.EmbeddingResponse {
54- Object : "list" ,
55- Model : request .Model ,
56- Data : []types.Embedding {{
53+ // 构造 OpenAI 兼容响应
54+ openaiData := make ([]types.Embedding , 0 )
55+ if len (ollamaResponse .Embeddings ) > 0 {
56+ for i , v := range ollamaResponse .Embeddings {
57+ openaiData = append (openaiData , types.Embedding {
58+ Object : "embedding" ,
59+ Index : i ,
60+ Embedding : v ,
61+ })
62+ }
63+ } else if len (ollamaResponse .Embedding ) > 0 {
64+ openaiData = append (openaiData , types.Embedding {
5765 Object : "embedding" ,
5866 Index : 0 ,
5967 Embedding : ollamaResponse .Embedding ,
60- }},
68+ })
69+ }
70+
71+ response := & types.EmbeddingResponse {
72+ Object : "list" ,
73+ Model : request .Model ,
74+ Data : openaiData ,
6175 Usage : & types.Usage {
62- TotalTokens : 0 ,
76+ PromptTokens : ollamaResponse . PromptEvalCount ,
6377 CompletionTokens : 0 ,
64- PromptTokens : 0 ,
78+ TotalTokens : ollamaResponse . PromptEvalCount ,
6579 },
6680 }
6781
Original file line number Diff line number Diff line change @@ -38,11 +38,16 @@ type Message struct {
3838}
3939
4040type EmbeddingRequest struct {
41- Model string `json:"model"`
42- Prompt string `json:"prompt "`
41+ Model string `json:"model"`
42+ Input any `json:"input "`
4343}
4444
4545type EmbeddingResponse struct {
4646 OllamaError
47- Embedding []float64 `json:"embedding,omitempty"`
47+ Model string `json:"model,omitempty"`
48+ Embeddings [][]float64 `json:"embeddings,omitempty"`
49+ Embedding []float64 `json:"embedding,omitempty"`
50+ TotalDuration int64 `json:"total_duration,omitempty"`
51+ LoadDuration int64 `json:"load_duration,omitempty"`
52+ PromptEvalCount int `json:"prompt_eval_count,omitempty"`
4853}
You can’t perform that action at this time.
0 commit comments