Skip to content

Commit 3d482bd

Browse files
feat: add g4f provider
1 parent 59123dc commit 3d482bd

File tree

3 files changed

+92
-5
lines changed

3 files changed

+92
-5
lines changed

readme.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ the translation of your favorite AI model (the first) is cached by default in **
1818
![app screenshot](imgs/screenshot-01.png)
1919

2020
## Models
21-
the available models are gemini, gpt-3.5-turbo, gpt-4o-mini, llama, cohere models
22-
other models: Qwen, DeepSeek, mixtral, nous mixtral, yi, and etc.
21+
the available models are:
22+
o1, claude-3-opus, claude-3.5-sonnet
23+
DeepSeek-R1, DeepSeek-V3, gpt-4o, gpt-4o-mini, gpt-3.5-turbo
24+
gemini, cohere models, Qwen, llama
25+
other models: mixtral, nous mixtral, yi, and etc.
2326

2427
there's also available: DeepLX, google translate, and SugoiV4
2528

src/providers/g4f.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { OpenAIChat } from "../global/lib";
2+
import { systemPrompt, userPrompt } from "../global/text";
3+
4+
5+
6+
export async function g4fHandler(text: string, model_name: string, tag: HTMLTextAreaElement) {
7+
if (!text || !tag || !model_name) { return "" }
8+
const client = new OpenAIChat("https://playmak3r-g4f.hf.space/v1/chat/completions", {
9+
model: model_name,
10+
system_prompt: systemPrompt
11+
})
12+
13+
tag.value = ""
14+
const stream = await client.sendPrompt(userPrompt({ text }))
15+
if (stream) {
16+
for await (const chunk of stream) {
17+
const text = chunk?.choices?.[0]?.delta?.content;
18+
if (text) { tag.value += text; }
19+
else if (chunk?.error) { tag.value = chunk.error?.message }
20+
else if (chunk) { console.log(chunk) }
21+
}
22+
}
23+
24+
return tag.value
25+
}
26+
27+
28+
export default {
29+
provider_name: "GPT4Free",
30+
api_key: undefined,
31+
models: [
32+
{
33+
name: "qwen-2.5-72b",
34+
owned_by: "Qwen",
35+
auto_fetch: false
36+
}, {
37+
name: "command-r-plus",
38+
owned_by: "cohere",
39+
auto_fetch: false
40+
}, {
41+
name: "grok-2",
42+
owned_by: "X AI",
43+
auto_fetch: false
44+
}, {
45+
name: "deepseek-r1",
46+
owned_by: "DeepSeek AI",
47+
auto_fetch: false
48+
}, {
49+
name: "deepseek-chat",
50+
owned_by: "DeepSeek AI",
51+
auto_fetch: false
52+
}, {
53+
name: "claude-3.5-sonnet",
54+
owned_by: "anthropic",
55+
auto_fetch: false
56+
}, {
57+
name: "claude-3-opus",
58+
owned_by: "anthropic",
59+
auto_fetch: false
60+
}, {
61+
name: "gpt-3.5-turbo",
62+
owned_by: "openai",
63+
auto_fetch: false
64+
}, {
65+
name: "gpt-4o-mini",
66+
owned_by: "openai",
67+
auto_fetch: false
68+
}, {
69+
name: "gpt-4o",
70+
owned_by: "openai",
71+
auto_fetch: false
72+
}, {
73+
name: "o1",
74+
owned_by: "openai",
75+
auto_fetch: false
76+
}, {
77+
name: "o1-mini",
78+
owned_by: "openai",
79+
auto_fetch: false
80+
},
81+
]
82+
}

src/providers/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Cohere, { CohereHandler } from './Cohere'
55
import HuggingFace, { HuggingFaceHandler } from './HuggingFace'
66
import Auto, { AutomaticHandler } from './Auto'
77
import OpenRouter, { OpenRouterHandler } from './openrouter-ai'
8+
import g4f, { g4fHandler } from './g4f'
89

910

1011

@@ -32,17 +33,18 @@ const Handlers = {
3233
Cohere: CohereHandler,
3334
Auto: AutomaticHandler,
3435
HuggingSpaces: HuggingSpacesHandler,
35-
OpenRouter: OpenRouterHandler
36+
OpenRouter: OpenRouterHandler,
37+
g4f: g4fHandler
3638
}
3739

3840
export function getHandler(provider_key: string, _: string):
3941
(text: string, model_name: string, tag: HTMLTextAreaElement) => Promise<string> {
4042
return Handlers[provider_key as keyof typeof Handlers]
4143
}
4244

43-
export { GroqCloud, Google, HuggingFace, Cohere, Auto, HuggingSpaces, OpenRouter }
45+
export { GroqCloud, Google, HuggingFace, Cohere, Auto, HuggingSpaces, OpenRouter, g4f }
4446

45-
const Providers = { GroqCloud, Google, HuggingFace, Cohere, Auto, HuggingSpaces, OpenRouter }
47+
const Providers = { GroqCloud, Google, HuggingFace, Cohere, Auto, HuggingSpaces, OpenRouter, g4f }
4648

4749
export type TProviderKeys = Exclude<keyof typeof Providers, "getModel">
4850

0 commit comments

Comments
 (0)