XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

feat: add AI Badgr as OpenAI-compatible provider

- Add AIBadgr provider class extending OpenaiTemplate - API endpoint: https://aibadgr.com/api/v1 - Full support for streaming, system messages, and message history - Add example usage script in etc/examples/aibadgr.py - Provider requires API key authentication

8516f167
michael m <55236695+michaelbrinkworth@users.noreply.github.com>
提交于

代码差异

3 个文件 +65 -0
Added etc/examples/aibadgr.py +50 -0
@@ -0,0 +1,50 @@
1 """
2 Example usage of AI Badgr provider.
3 AI Badgr is an OpenAI-compatible API provider.
4 Get your API key at: https://aibadgr.com/api-keys
5
6 Usage:
7 export AIBADGR_API_KEY="your-api-key-here"
8 python aibadgr.py
9 """
10
11 from g4f.client import Client
12 from g4f.Provider import AIBadgr
13
14 # Using AI Badgr with the g4f client
15 client = Client(
16 provider=AIBadgr,
17 api_key="your-api-key-here" # Or set AIBADGR_API_KEY environment variable
18 )
19
20 # Example 1: Simple chat completion
21 print("Example 1: Simple chat completion")
22 response = client.chat.completions.create(
23 model="gpt-4o-mini", # AI Badgr supports OpenAI-compatible models
24 messages=[{"role": "user", "content": "Hello! What can you help me with?"}]
25 )
26 print(response.choices[0].message.content)
27 print()
28
29 # Example 2: Streaming response
30 print("Example 2: Streaming response")
31 response = client.chat.completions.create(
32 model="gpt-4o-mini",
33 messages=[{"role": "user", "content": "Count from 1 to 5"}],
34 stream=True
35 )
36 for chunk in response:
37 if chunk.choices[0].delta.content:
38 print(chunk.choices[0].delta.content, end="", flush=True)
39 print("\n")
40
41 # Example 3: With system message
42 print("Example 3: With system message")
43 response = client.chat.completions.create(
44 model="gpt-4o-mini",
45 messages=[
46 {"role": "system", "content": "You are a helpful assistant that speaks like a pirate."},
47 {"role": "user", "content": "Tell me about the weather"}
48 ]
49 )
50 print(response.choices[0].message.content)
Added g4f/Provider/needs_auth/AIBadgr.py +14 -0
@@ -0,0 +1,14 @@
1 from __future__ import annotations
2
3 from ..template import OpenaiTemplate
4
5 class AIBadgr(OpenaiTemplate):
6 label = "AI Badgr"
7 url = "https://aibadgr.com"
8 login_url = "https://aibadgr.com/api-keys"
9 api_base = "https://aibadgr.com/api/v1"
10 working = True
11 needs_auth = True
12 supports_stream = True
13 supports_system_message = True
14 supports_message_history = True
Modified g4f/Provider/needs_auth/__init__.py +1 -0
@@ -1,3 +1,4 @@
1 from .AIBadgr import AIBadgr
1 2 from .Anthropic import Anthropic
2 3 from .Azure import Azure
3 4 from .BingCreateImages import BingCreateImages