feat : better web form handling

This commit is contained in:
martin legrand
2025-04-13 17:23:00 +02:00
parent 5b491ddbf7
commit e0f0c5c7f6
9 changed files with 173 additions and 36 deletions
+23 -1
View File
@@ -28,6 +28,7 @@ class Provider:
"lm-studio": self.lm_studio_fn,
"huggingface": self.huggingface_fn,
"deepseek": self.deepseek_fn,
"together": self.together_fn,
"dsk_deepseek": self.dsk_deepseek,
"test": self.test_fn
}
@@ -122,7 +123,7 @@ class Provider:
route_gen = f"http://{self.server_ip}/generate"
if not self.is_ip_online(self.server_ip.split(":")[0]):
raise Exception(f"Server is offline at {self.server_ip}")
pretty_print(f"Server is offline at {self.server_ip}", color="failure")
try:
requests.post(route_setup, json={"model": self.model})
@@ -219,6 +220,27 @@ class Provider:
except Exception as e:
raise Exception(f"OpenAI API error: {str(e)}") from e
def together_fn(self, history, verbose=False):
"""
Use together AI for completion
"""
from together import Together
client = Together(api_key=self.api_key)
try:
response = client.chat.completions.create(
model=self.model,
messages=history,
)
if response is None:
raise Exception("Together AI response is empty.")
thought = response.choices[0].message.content
if verbose:
print(thought)
return thought
except Exception as e:
raise Exception(f"Together AI API error: {str(e)}") from e
def deepseek_fn(self, history, verbose=False):
"""
Use deepseek api to generate text.