DevsDoCode commited on
Commit
16e513e
1 Parent(s): 4abe385

Upload 2 files

Browse files
Files changed (2) hide show
  1. api_call.py +73 -11
  2. api_info.py +4 -7
api_call.py CHANGED
@@ -1,15 +1,77 @@
1
  import requests
 
2
 
3
- def generate_request(conversation_history):
4
- url = "https://devsdocode-bing.hf.space/generate"
5
- params = {
6
- "conversation_history": conversation_history,
7
- }
8
- response = requests.get(url, params=params)
9
- return response.text
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  if __name__ == "__main__":
12
- # Example usage:
13
- query = [{"role": "user", "content": "Who is Devs Do Code"}]
14
- response = generate_request(query)
15
- print(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import requests
2
+ import json
3
 
4
+ class BingChatAPI:
5
+ def __init__(self, base_url="https://devsdocode-bing.hf.space"):
6
+ self.base_url = base_url
 
 
 
 
7
 
8
+ def generate(self, conversation_history, realtime=False, md_format=True):
9
+ """
10
+ Generate a response using the Bing Chat API.
11
+
12
+ Args:
13
+ conversation_history (list or str): A list of message objects or a string query.
14
+ realtime (bool): Whether to stream the response in real-time.
15
+ md_format (bool): Whether to format the response in Markdown.
16
+
17
+ Returns:
18
+ dict: The API response.
19
+ """
20
+ endpoint = f"{self.base_url}/generate"
21
+
22
+ if isinstance(conversation_history, str):
23
+ conversation_history = [{"role": "user", "content": conversation_history}]
24
+
25
+ params = {
26
+ "conversation_history": json.dumps(conversation_history),
27
+ "realtime": str(realtime).lower(),
28
+ "md_format": str(md_format).lower()
29
+ }
30
+
31
+ response = requests.get(endpoint, params=params)
32
+ response.raise_for_status() # Raise an exception for bad status codes
33
+
34
+ return response.json()
35
+
36
+ def get_available_models(self):
37
+ """Get the list of available models."""
38
+ endpoint = f"{self.base_url}/available_models"
39
+ response = requests.get(endpoint)
40
+ response.raise_for_status()
41
+ return response.json()
42
+
43
+ def get_endpoints(self):
44
+ """Get the list of available endpoints."""
45
+ endpoint = f"{self.base_url}/endpoints"
46
+ response = requests.get(endpoint)
47
+ response.raise_for_status()
48
+ return response.json()
49
+
50
+ def get_developer_info(self):
51
+ """Get the developer information."""
52
+ endpoint = f"{self.base_url}/developer_info"
53
+ response = requests.get(endpoint)
54
+ response.raise_for_status()
55
+ return response.json()
56
+
57
+
58
+ # Example usage
59
  if __name__ == "__main__":
60
+ api = BingChatAPI()
61
+
62
+ # Generate a response
63
+ conversation = [{"role": "user", "content": "Who is Devs Do Code"}]
64
+ response = api.generate(conversation)
65
+ print("Generated Response:", response)
66
+
67
+ # Get available models
68
+ models = api.get_available_models()
69
+ print("Available Models:", models)
70
+
71
+ # Get endpoints
72
+ endpoints = api.get_endpoints()
73
+ print("Endpoints:", endpoints)
74
+
75
+ # Get developer info
76
+ dev_info = api.get_developer_info()
77
+ print("Developer Info:", dev_info)
api_info.py CHANGED
@@ -16,21 +16,18 @@ developer_info = {
16
  endpoint = {
17
  'route': "/generate",
18
  'params': {
19
- "query": "[SEARCH QUERY]"
20
  },
21
  'optional_params': {
22
- "max_tokens": "[]",
23
- "model": "[]",
24
- "temperature": "[]",
25
- "system_prompt": "[]"
26
  },
27
- 'url_demo' : '/generate?conversation_history=[{"role": "user", "content": "Who is Devs Do Code"}]'
28
  }
29
 
30
  available_models = {
31
  "Bing": "Bing Chat Copilot"
32
  }
33
-
34
  error_message = {
35
  'developer_contact': {
36
  'Telegram': 'https://t.me/DevsDoCode',
 
16
  endpoint = {
17
  'route': "/generate",
18
  'params': {
19
+ "conversation_history": "[CONVERSATION HISTORY]"
20
  },
21
  'optional_params': {
22
+ "realtime": "[true/false]",
23
+ "md_format": "[true/false]"
 
 
24
  },
25
+ 'url_demo': '/generate?conversation_history=[{"role": "user", "content": "Who is Devs Do Code"}]&realtime=false&md_format=true'
26
  }
27
 
28
  available_models = {
29
  "Bing": "Bing Chat Copilot"
30
  }
 
31
  error_message = {
32
  'developer_contact': {
33
  'Telegram': 'https://t.me/DevsDoCode',