mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-05 00:33:45 +08:00
sync upstream code
This commit is contained in:
@@ -2,6 +2,7 @@ import { getClientConfig } from "../config/client";
|
||||
import { ACCESS_CODE_PREFIX } from "../constant";
|
||||
import { ChatMessage, ModelType, useAccessStore } from "../store";
|
||||
import { ChatGPTApi } from "./platforms/openai";
|
||||
import { DuckDuckGoSearch } from "./tools/ddg_search";
|
||||
|
||||
export const ROLES = ["system", "user", "assistant"] as const;
|
||||
export type MessageRole = (typeof ROLES)[number];
|
||||
@@ -12,6 +13,7 @@ export type ChatModel = ModelType;
|
||||
export interface RequestMessage {
|
||||
role: MessageRole;
|
||||
content: string;
|
||||
toolPrompt?: string;
|
||||
}
|
||||
|
||||
export interface LLMConfig {
|
||||
@@ -70,11 +72,19 @@ interface ChatProvider {
|
||||
usage: () => void;
|
||||
}
|
||||
|
||||
export abstract class ToolApi {
|
||||
abstract call(input: string): Promise<string>;
|
||||
abstract name: string;
|
||||
abstract description: string;
|
||||
}
|
||||
|
||||
export class ClientApi {
|
||||
public llm: LLMApi;
|
||||
public searchTool: ToolApi;
|
||||
|
||||
constructor() {
|
||||
this.llm = new ChatGPTApi();
|
||||
this.searchTool = new DuckDuckGoSearch();
|
||||
}
|
||||
|
||||
config() {}
|
||||
|
||||
@@ -44,7 +44,7 @@ export class ChatGPTApi implements LLMApi {
|
||||
async chat(options: ChatOptions) {
|
||||
const messages = options.messages.map((v) => ({
|
||||
role: v.role,
|
||||
content: v.content,
|
||||
content: v.toolPrompt ?? v.content,
|
||||
}));
|
||||
|
||||
const modelConfig = {
|
||||
|
||||
15
app/client/tools/ddg_search.ts
Normal file
15
app/client/tools/ddg_search.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { ToolApi, getHeaders } from "../api";
|
||||
|
||||
export class DuckDuckGoSearch implements ToolApi {
|
||||
name = "duckduckgo_search";
|
||||
description =
|
||||
"A wrapper around DuckDuckGo Search.Useful for when you need to answer questions about current events.Input should be a search query.";
|
||||
|
||||
async call(input: string): Promise<string> {
|
||||
const res = await fetch(`/api/tools/ddg?query=${input}`, {
|
||||
method: "GET",
|
||||
headers: getHeaders(),
|
||||
});
|
||||
return await res.json();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user