infinitymatter commited on
Commit
a103ecb
·
verified ·
1 Parent(s): 814ade4

Update src/models.py

Browse files
Files changed (1) hide show
  1. src/models.py +8 -35
src/models.py CHANGED
@@ -4,54 +4,27 @@ import os
4
  from dotenv import load_dotenv
5
  from huggingface_hub import HfApi;
6
 
 
7
  # Load environment variables from .env file
8
  load_dotenv(override=True)
9
 
10
- # Retrieve API keys from environment
11
- openai_api_key = os.getenv("OPENAI_API_KEY")
12
- anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
13
 
14
- # Warn if any API key is missing
15
- if not openai_api_key:
16
- print(" OpenAI API Key is missing!")
17
 
18
- if not anthropic_api_key:
19
- print("❌ Anthropic API Key is missing!")
20
-
21
- # Initialize API clients
22
- openai = HfApi(token=openai_api_key)
23
- claude = HfApi(token=anthropic_api_key)
24
-
25
- # Model names
26
- OPENAI_MODEL = "mistralai/Mistral-7B-Instruct-v0.3"
27
- CLAUDE_MODEL = "mistralai/Mistral-7B-Instruct-v0.3"
28
-
29
- # Call OpenAI's GPT model with prompt and system message
30
  def get_gpt_completion(prompt, system_message):
31
  try:
32
- response = openai.chat.completions.create(
33
- model=OPENAI_MODEL,
34
- messages=[
35
- {"role": "system", "content": system_message},
36
- {"role": "user", "content": prompt}
37
- ],
38
- stream=False,
39
- )
40
- return response.choices[0].message.content
41
  except Exception as e:
42
  print(f"GPT error: {e}")
43
  raise
44
 
45
- # Call Anthropic's Claude model with prompt and system message
46
  def get_claude_completion(prompt, system_message):
47
  try:
48
- result = claude.messages.create(
49
- model=CLAUDE_MODEL,
50
- max_tokens=2000,
51
- system=system_message,
52
- messages=[{"role": "user", "content": prompt}]
53
- )
54
- return result.content[0].text
55
  except Exception as e:
56
  print(f"Claude error: {e}")
57
  raise
 
4
  from dotenv import load_dotenv
5
  from huggingface_hub import HfApi;
6
 
7
+ from huggingface_hub import InferenceClient
8
  # Load environment variables from .env file
9
  load_dotenv(override=True)
10
 
 
 
 
11
 
12
+ # Initialize disguised API clients
13
+ openai = InferenceClient(model="mistralai/Mistral-7B-Instruct-v0.3", token=openai_api_key)
14
+ claude = InferenceClient(model="mistralai/Mistral-7B-Instruct-v0.3", token=anthropic_api_key)
15
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def get_gpt_completion(prompt, system_message):
17
  try:
18
+ response = openai.text_generation(prompt=f"{system_message}\n{prompt}", max_new_tokens=200)
19
+ return response
 
 
 
 
 
 
 
20
  except Exception as e:
21
  print(f"GPT error: {e}")
22
  raise
23
 
 
24
  def get_claude_completion(prompt, system_message):
25
  try:
26
+ response = claude.text_generation(prompt=f"{system_message}\n{prompt}", max_new_tokens=200)
27
+ return response
 
 
 
 
 
28
  except Exception as e:
29
  print(f"Claude error: {e}")
30
  raise