This commit is contained in:
1 parent
c6088aeb4b
commit
f12128a5c3
4 files changed
+136
-33
No files matched your search
@@ -90,7 +90,19 @@ type fakeTranslateChat struct {
|
||||
prompts []string
|
||||
}
|
||||
|
||||
func (f *fakeTranslateChat) Chat(_ context.Context, messages []chat.Message, _ *chat.ChatOptions) (*types.ChatResponse, error) {
|
||||
func (f *fakeTranslateChat) Chat(ctx context.Context, messages []chat.Message, opts *chat.ChatOptions) (*types.ChatResponse, error) {
|
||||
resp, err := f.ChatStream(ctx, messages, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var content strings.Builder
|
||||
for chunk := range resp {
|
||||
content.WriteString(chunk.Content)
|
||||
}
|
||||
return &types.ChatResponse{Content: content.String()}, nil
|
||||
}
|
||||
|
||||
func (f *fakeTranslateChat) ChatStream(_ context.Context, messages []chat.Message, _ *chat.ChatOptions) (<-chan types.StreamResponse, error) {
|
||||
f.prompts = append(f.prompts, messages[len(messages)-1].Content)
|
||||
content := messages[len(messages)-1].Content
|
||||
start := strings.IndexByte(content, '[')
|
||||
@@ -104,11 +116,11 @@ func (f *fakeTranslateChat) Chat(_ context.Context, messages []chat.Message, _ *
|
||||
out = append(out, replaceCJKRuns(t))
|
||||
}
|
||||
b, _ := json.Marshal(out)
|
||||
return &types.ChatResponse{Content: string(b)}, nil
|
||||
}
|
||||
|
||||
func (f *fakeTranslateChat) ChatStream(_ context.Context, _ []chat.Message, _ *chat.ChatOptions) (<-chan types.StreamResponse, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
ch := make(chan types.StreamResponse, 2)
|
||||
ch <- types.StreamResponse{ResponseType: types.ResponseTypeAnswer, Content: string(b)}
|
||||
ch <- types.StreamResponse{ResponseType: types.ResponseTypeAnswer, Done: true}
|
||||
close(ch)
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func (f *fakeTranslateChat) GetModelName() string { return "fake" }
|
||||
|
||||
Reference in new issue
Block a user