Guiyom commited on
Commit
eb00ff4
·
verified ·
1 Parent(s): 74df59c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -1,5 +1,7 @@
 
 
1
  import gradio as gr
2
- import openai
3
  import requests
4
  import json
5
  import os
@@ -18,7 +20,7 @@ class RaindropSearchBot:
18
  def __init__(self):
19
  self.openai_api_key = OPENAI_API_KEY
20
  self.raindrop_api_token = RAINDROP_TOKEN
21
- openai.api_key = self.openai_api_key
22
 
23
  def generate_search_query(self, user_request: str) -> str:
24
  """Convert user request to a tailored search query using OpenAI."""
@@ -31,15 +33,13 @@ class RaindropSearchBot:
31
  Format the search query with relevant keywords and operators if needed.
32
  """
33
 
34
- response = openai.ChatCompletion.create(
35
- model="gpt-3.5-turbo",
36
- messages=[
37
- {"role": "system", "content": "You are a search query optimization assistant."},
38
- {"role": "user", "content": prompt}
39
- ]
40
  )
41
-
42
- return response.choices[0].message.content.strip()
43
 
44
  def search_raindrop(self, search_query: str) -> List[Dict]:
45
  """Search Raindrop.io with the generated query."""
@@ -122,7 +122,8 @@ with gr.Blocks(title="Raindrop.io Link Search Assistant", theme=gr.themes.Soft()
122
  with gr.Row():
123
  output_text = gr.Textbox(
124
  label="Search Results",
125
- lines=10
 
126
  )
127
 
128
  search_button.click(
@@ -142,4 +143,4 @@ with gr.Blocks(title="Raindrop.io Link Search Assistant", theme=gr.themes.Soft()
142
 
143
  # Launch the interface
144
  if __name__ == "__main__":
145
- demo.launch(share=True)
 
1
+ python
2
+
3
  import gradio as gr
4
+ from openai import OpenAI
5
  import requests
6
  import json
7
  import os
 
20
  def __init__(self):
21
  self.openai_api_key = OPENAI_API_KEY
22
  self.raindrop_api_token = RAINDROP_TOKEN
23
+ self.client = OpenAI(api_key=self.openai_api_key)
24
 
25
  def generate_search_query(self, user_request: str) -> str:
26
  """Convert user request to a tailored search query using OpenAI."""
 
33
  Format the search query with relevant keywords and operators if needed.
34
  """
35
 
36
+ response = self.client.chat.completions.create(
37
+ model="gpt-4o-mini",
38
+ messages=[{"role": "user", "content": prompt}],
39
+ temperature=0.5,
40
+ max_tokens=1000
 
41
  )
42
+ return response.choices[0].message.content
 
43
 
44
  def search_raindrop(self, search_query: str) -> List[Dict]:
45
  """Search Raindrop.io with the generated query."""
 
122
  with gr.Row():
123
  output_text = gr.Textbox(
124
  label="Search Results",
125
+ lines=10,
126
+ readonly=True
127
  )
128
 
129
  search_button.click(
 
143
 
144
  # Launch the interface
145
  if __name__ == "__main__":
146
+ demo.launch(share=True)