Skip to content

Commit 5d5ea3e

Browse files
authored
Merge pull request #1689 from ScriptScientist/main
feat: novita llms support
2 parents 2c2dbe4 + 867c375 commit 5d5ea3e

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

application/api/answer/routes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
gpt_model = "claude-2"
4343
elif settings.LLM_NAME == "groq":
4444
gpt_model = "llama3-8b-8192"
45+
elif settings.LLM_NAME == "novita":
46+
gpt_model = "deepseek/deepseek-r1"
4547

4648
if settings.MODEL_NAME: # in case there is particular model name configured
4749
gpt_model = settings.MODEL_NAME

application/llm/llm_creator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from application.llm.docsgpt_provider import DocsGPTAPILLM
88
from application.llm.premai import PremAILLM
99
from application.llm.google_ai import GoogleLLM
10-
10+
from application.llm.novita import NovitaLLM
1111

1212
class LLMCreator:
1313
llms = {
@@ -20,7 +20,8 @@ class LLMCreator:
2020
"docsgpt": DocsGPTAPILLM,
2121
"premai": PremAILLM,
2222
"groq": GroqLLM,
23-
"google": GoogleLLM
23+
"google": GoogleLLM,
24+
"novita": NovitaLLM
2425
}
2526

2627
@classmethod

application/llm/novita.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from application.llm.base import BaseLLM
2+
from openai import OpenAI
3+
4+
5+
class NovitaLLM(BaseLLM):
6+
def __init__(self, api_key=None, user_api_key=None, *args, **kwargs):
7+
super().__init__(*args, **kwargs)
8+
self.client = OpenAI(api_key=api_key, base_url="https://api.novita.ai/v3/openai")
9+
self.api_key = api_key
10+
self.user_api_key = user_api_key
11+
12+
def _raw_gen(self, baseself, model, messages, stream=False, tools=None, **kwargs):
13+
if tools:
14+
response = self.client.chat.completions.create(
15+
model=model, messages=messages, stream=stream, tools=tools, **kwargs
16+
)
17+
return response.choices[0]
18+
else:
19+
response = self.client.chat.completions.create(
20+
model=model, messages=messages, stream=stream, **kwargs
21+
)
22+
return response.choices[0].message.content
23+
24+
def _raw_gen_stream(
25+
self, baseself, model, messages, stream=True, tools=None, **kwargs
26+
):
27+
response = self.client.chat.completions.create(
28+
model=model, messages=messages, stream=stream, **kwargs
29+
)
30+
for line in response:
31+
if line.choices[0].delta.content is not None:
32+
yield line.choices[0].delta.content

setup.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ prompt_cloud_api_provider_options() {
148148
echo -e "${YELLOW}4) Groq${NC}"
149149
echo -e "${YELLOW}5) HuggingFace Inference API${NC}"
150150
echo -e "${YELLOW}6) Azure OpenAI${NC}"
151+
echo -e "${YELLOW}7) Novita${NC}"
151152
echo -e "${YELLOW}b) Back to Main Menu${NC}"
152153
echo
153154
read -p "$(echo -e "${DEFAULT_FG}Choose option (1-6, or b): ${NC}")" provider_choice
@@ -428,6 +429,12 @@ connect_cloud_api_provider() {
428429
model_name="gpt-4o"
429430
get_api_key
430431
break ;;
432+
7) # Novita
433+
provider_name="Novita"
434+
llm_name="novita"
435+
model_name="deepseek/deepseek-r1"
436+
get_api_key
437+
break ;;
431438
b|B) clear; return ;; # Clear screen and Back to Main Menu
432439
*) echo -e "\n${RED}Invalid choice. Please choose 1-6, or b.${NC}" ; sleep 1 ;;
433440
esac

0 commit comments

Comments
 (0)