Spaces:
Sleeping
Sleeping
Add OpenRouter-Auto
Browse files- llm_client.py +21 -8
- main.py +3 -2
- openrouter_client.py +1 -1
- ui_components.py +3 -3
llm_client.py
CHANGED
@@ -28,6 +28,19 @@ class LLMClient:
|
|
28 |
"""Enable or disable test mode for simulating errors"""
|
29 |
self.test_mode = enabled
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
def chat_openai(self, messages: List[Dict[str, str]]) -> str:
|
32 |
"""Send chat completion request to OpenAI API"""
|
33 |
if not self.openai_client:
|
@@ -52,31 +65,31 @@ class LLMClient:
|
|
52 |
except openai.APIError as e:
|
53 |
raise Exception(f"OpenAI API error: {str(e)}")
|
54 |
|
55 |
-
def
|
56 |
-
"""Send chat completion request to
|
57 |
if not self.openrouter_client:
|
58 |
raise ValueError("OpenRouter client not initialized. Please check your API key.")
|
59 |
|
60 |
try:
|
61 |
return self.openrouter_client.create(
|
62 |
messages=messages,
|
63 |
-
model=Config.
|
64 |
)
|
65 |
except Exception as e:
|
66 |
-
raise Exception(f"
|
67 |
|
68 |
-
def
|
69 |
-
"""Send chat completion request to
|
70 |
if not self.openrouter_client:
|
71 |
raise ValueError("OpenRouter client not initialized. Please check your API key.")
|
72 |
|
73 |
try:
|
74 |
return self.openrouter_client.create(
|
75 |
messages=messages,
|
76 |
-
model=Config.
|
77 |
)
|
78 |
except Exception as e:
|
79 |
-
raise Exception(f"
|
80 |
|
81 |
def generate_context_summary(self, messages: List[Dict[str, str]]) -> str:
|
82 |
"""Generate a summary of the conversation context."""
|
|
|
28 |
"""Enable or disable test mode for simulating errors"""
|
29 |
self.test_mode = enabled
|
30 |
|
31 |
+
def chat_auto(self, messages: List[Dict[str, str]]) -> str:
|
32 |
+
"""Send chat completion request to Auto via OpenRouter"""
|
33 |
+
if not self.openrouter_client:
|
34 |
+
raise ValueError("OpenRouter client not initialized. Please check your API key.")
|
35 |
+
|
36 |
+
try:
|
37 |
+
return self.openrouter_client.create(
|
38 |
+
messages=messages,
|
39 |
+
model=Config.AUTO_MODEL
|
40 |
+
)
|
41 |
+
except Exception as e:
|
42 |
+
raise Exception(f"OpenRouter AUTO API error: {str(e)}")
|
43 |
+
|
44 |
def chat_openai(self, messages: List[Dict[str, str]]) -> str:
|
45 |
"""Send chat completion request to OpenAI API"""
|
46 |
if not self.openai_client:
|
|
|
65 |
except openai.APIError as e:
|
66 |
raise Exception(f"OpenAI API error: {str(e)}")
|
67 |
|
68 |
+
def chat_claude(self, messages: List[Dict[str, str]]) -> str:
|
69 |
+
"""Send chat completion request to Claude via OpenRouter"""
|
70 |
if not self.openrouter_client:
|
71 |
raise ValueError("OpenRouter client not initialized. Please check your API key.")
|
72 |
|
73 |
try:
|
74 |
return self.openrouter_client.create(
|
75 |
messages=messages,
|
76 |
+
model=Config.CLAUDE_MODEL
|
77 |
)
|
78 |
except Exception as e:
|
79 |
+
raise Exception(f"Claude API error: {str(e)}")
|
80 |
|
81 |
+
def chat_gemini(self, messages: List[Dict[str, str]]) -> str:
|
82 |
+
"""Send chat completion request to Gemini via OpenRouter"""
|
83 |
if not self.openrouter_client:
|
84 |
raise ValueError("OpenRouter client not initialized. Please check your API key.")
|
85 |
|
86 |
try:
|
87 |
return self.openrouter_client.create(
|
88 |
messages=messages,
|
89 |
+
model=Config.GEMINI_MODEL
|
90 |
)
|
91 |
except Exception as e:
|
92 |
+
raise Exception(f"Gemini API error: {str(e)}")
|
93 |
|
94 |
def generate_context_summary(self, messages: List[Dict[str, str]]) -> str:
|
95 |
"""Generate a summary of the conversation context."""
|
main.py
CHANGED
@@ -205,9 +205,10 @@ def main():
|
|
205 |
|
206 |
# Model selection logic
|
207 |
model_map = {
|
|
|
208 |
"GPT-4": llm_client.chat_openai,
|
209 |
-
"
|
210 |
-
"
|
211 |
}
|
212 |
|
213 |
if model in model_map:
|
|
|
205 |
|
206 |
# Model selection logic
|
207 |
model_map = {
|
208 |
+
"OpenRouter-Auto": llm_client.chat_auto,
|
209 |
"GPT-4": llm_client.chat_openai,
|
210 |
+
"Claude-3.5": llm_client.chat_claude,
|
211 |
+
"Gemini-2.0": llm_client.chat_gemini
|
212 |
}
|
213 |
|
214 |
if model in model_map:
|
openrouter_client.py
CHANGED
@@ -30,7 +30,7 @@ class OpenRouterClient:
|
|
30 |
}
|
31 |
|
32 |
data = {
|
33 |
-
"model": model or Config.
|
34 |
"messages": messages,
|
35 |
"temperature": 0.7,
|
36 |
"max_tokens": 1000
|
|
|
30 |
}
|
31 |
|
32 |
data = {
|
33 |
+
"model": model or Config.AUTO_MODEL,
|
34 |
"messages": messages,
|
35 |
"temperature": 0.7,
|
36 |
"max_tokens": 1000
|
ui_components.py
CHANGED
@@ -49,11 +49,11 @@ def render_sidebar(i18n, chat_manager):
|
|
49 |
key="language_selector"
|
50 |
)
|
51 |
|
52 |
-
# Model selection - デフォルトを
|
53 |
model = st.selectbox(
|
54 |
i18n.get_text("model_selection"),
|
55 |
-
["
|
56 |
-
index=
|
57 |
key="model_selection"
|
58 |
)
|
59 |
|
|
|
49 |
key="language_selector"
|
50 |
)
|
51 |
|
52 |
+
# Model selection - デフォルトをOpenRouter-Autoに設定
|
53 |
model = st.selectbox(
|
54 |
i18n.get_text("model_selection"),
|
55 |
+
["OpenRouter-Auto", "GPT-4", "Claude-3.5", "Gemini-2.0"],
|
56 |
+
index=0,
|
57 |
key="model_selection"
|
58 |
)
|
59 |
|