eljanmahammadli commited on
Commit
b72ef7f
·
1 Parent(s): 34b1950

modified temperature and max_tokens

Browse files
Files changed (2) hide show
  1. ai_generate.py +22 -15
  2. app.py +6 -8
ai_generate.py CHANGED
@@ -42,27 +42,35 @@ vertexai.init(project="proprietary-info-detection", location="us-central1")
42
  gemini_client = GenerativeModel("gemini-1.5-pro-001")
43
  claude_client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
44
 
 
 
 
45
 
46
  rag_llms = {
47
  "LLaMA 3": ChatGroq(
48
- temperature=0,
 
49
  model_name="llama3-70b-8192",
50
  ),
51
  "OpenAI GPT 4o Mini": ChatOpenAI(
52
- temperature=0,
 
53
  model_name="gpt-4o-mini",
54
  ),
55
  "OpenAI GPT 4o": ChatOpenAI(
56
- temperature=0,
 
57
  model_name="gpt-4o",
58
  ),
59
  "OpenAI GPT 4": ChatOpenAI(
60
- temperature=0,
 
61
  model_name="gpt-4-turbo",
62
  ),
63
- "Gemini 1.5 Pro": ChatGoogleGenerativeAI(temperature=0, model="gemini-1.5-pro"),
64
  "Claude Sonnet 3.5": ChatAnthropic(
65
- temperature=0,
 
66
  model_name="claude-3-5-sonnet-20240620",
67
  ),
68
  }
@@ -107,8 +115,8 @@ def generate_groq(text, model):
107
  "content": "Please follow the instruction and write about the given topic in approximately the given number of words",
108
  },
109
  ],
110
- temperature=1,
111
- max_tokens=1024,
112
  stream=True,
113
  stop=None,
114
  )
@@ -124,8 +132,8 @@ def generate_openai(text, model, openai_client):
124
  response = openai_client.chat.completions.create(
125
  model=model,
126
  messages=message,
127
- temperature=1,
128
- max_tokens=1024,
129
  )
130
  return response.choices[0].message.content
131
 
@@ -138,9 +146,8 @@ def generate_gemini(text, model, gemini_client):
138
  generative_models.HarmCategory.HARM_CATEGORY_HARASSMENT: generative_models.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
139
  }
140
  generation_config = {
141
- "max_output_tokens": 1024,
142
- "temperature": 1.0,
143
- "top_p": 1.0,
144
  }
145
  response = gemini_client.generate_content(
146
  [text],
@@ -154,8 +161,8 @@ def generate_gemini(text, model, gemini_client):
154
  def generate_claude(text, model, claude_client):
155
  response = claude_client.messages.create(
156
  model=model,
157
- max_tokens=1024,
158
- temperature=1.0,
159
  system="You are helpful assistant.",
160
  messages=[{"role": "user", "content": [{"type": "text", "text": text}]}],
161
  )
 
42
  gemini_client = GenerativeModel("gemini-1.5-pro-001")
43
  claude_client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
44
 
45
+ # For GPT-4 1 word is about 1.3 tokens.
46
+ temperature = 1.0
47
+ max_tokens = 2048
48
 
49
  rag_llms = {
50
  "LLaMA 3": ChatGroq(
51
+ temperature=temperature,
52
+ max_tokens=max_tokens,
53
  model_name="llama3-70b-8192",
54
  ),
55
  "OpenAI GPT 4o Mini": ChatOpenAI(
56
+ temperature=temperature,
57
+ max_tokens=max_tokens,
58
  model_name="gpt-4o-mini",
59
  ),
60
  "OpenAI GPT 4o": ChatOpenAI(
61
+ temperature=temperature,
62
+ max_tokens=max_tokens,
63
  model_name="gpt-4o",
64
  ),
65
  "OpenAI GPT 4": ChatOpenAI(
66
+ temperature=temperature,
67
+ max_tokens=max_tokens,
68
  model_name="gpt-4-turbo",
69
  ),
70
+ "Gemini 1.5 Pro": ChatGoogleGenerativeAI(temperature=temperature, max_tokens=max_tokens, model="gemini-1.5-pro"),
71
  "Claude Sonnet 3.5": ChatAnthropic(
72
+ temperature=temperature,
73
+ max_tokens=max_tokens,
74
  model_name="claude-3-5-sonnet-20240620",
75
  ),
76
  }
 
115
  "content": "Please follow the instruction and write about the given topic in approximately the given number of words",
116
  },
117
  ],
118
+ temperature=temperature,
119
+ max_tokens=max_tokens,
120
  stream=True,
121
  stop=None,
122
  )
 
132
  response = openai_client.chat.completions.create(
133
  model=model,
134
  messages=message,
135
+ temperature=temperature,
136
+ max_tokens=max_tokens,
137
  )
138
  return response.choices[0].message.content
139
 
 
146
  generative_models.HarmCategory.HARM_CATEGORY_HARASSMENT: generative_models.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
147
  }
148
  generation_config = {
149
+ "max_output_tokens": max_tokens,
150
+ "temperature": temperature,
 
151
  }
152
  response = gemini_client.generate_content(
153
  [text],
 
161
  def generate_claude(text, model, claude_client):
162
  response = claude_client.messages.create(
163
  model=model,
164
+ max_tokens=max_tokens,
165
+ temperature=temperature,
166
  system="You are helpful assistant.",
167
  messages=[{"role": "user", "content": [{"type": "text", "text": text}]}],
168
  )
app.py CHANGED
@@ -2,20 +2,18 @@
2
  nohup python3 app.py &
3
  """
4
 
5
- import openai
6
- import gradio as gr
7
- from typing import Dict, List
8
  import re
9
  import requests
 
 
 
 
 
10
  import language_tool_python
 
11
  import torch
12
- from gradio_client import Client
13
  from transformers import GPT2LMHeadModel, GPT2TokenizerFast
14
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
15
- from scipy.special import softmax
16
- from collections import defaultdict
17
- import nltk
18
- from datetime import date
19
 
20
  from utils import remove_special_characters
21
  from plagiarism import google_search, months, domain_list, build_date
 
2
  nohup python3 app.py &
3
  """
4
 
 
 
 
5
  import re
6
  import requests
7
+ from typing import Dict
8
+ from collections import defaultdict
9
+ from datetime import date
10
+ import gradio as gr
11
+ from scipy.special import softmax
12
  import language_tool_python
13
+ import nltk
14
  import torch
 
15
  from transformers import GPT2LMHeadModel, GPT2TokenizerFast
16
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
 
 
 
 
17
 
18
  from utils import remove_special_characters
19
  from plagiarism import google_search, months, domain_list, build_date