chipling commited on
Commit
0e1636e
·
verified ·
1 Parent(s): 0f00e90

Upload 24 files

Browse files
__pycache__/app.cpython-311.pyc ADDED
Binary file (8.08 kB). View file
 
app.py CHANGED
@@ -5,6 +5,7 @@ from models.text.together.main import TogetherAPI
5
  from models.text.vercel.main import XaiAPI, GroqAPI, DeepinfraAPI
6
  from models.image.vercel.main import FalAPI
7
  from models.image.together.main import TogetherImageAPI
 
8
 
9
  app = FastAPI()
10
 
@@ -110,5 +111,68 @@ async def generate_images(request: Request):
110
  response = await streamModel.generate(query)
111
  return response
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  except Exception as e:
114
  return {"error": f"An error occurred: {str(e)}"}
 
5
  from models.text.vercel.main import XaiAPI, GroqAPI, DeepinfraAPI
6
  from models.image.vercel.main import FalAPI
7
  from models.image.together.main import TogetherImageAPI
8
+ from models.fetch import FetchModel
9
 
10
  app = FastAPI()
11
 
 
111
  response = await streamModel.generate(query)
112
  return response
113
 
114
+ except Exception as e:
115
+ return {"error": f"An error occurred: {str(e)}"}
116
+
117
+
118
+ @app.get('/api/v1/fetch-models')
119
+ async def fetch_models():
120
+ model = FetchModel()
121
+ return model.all_models()
122
+
123
+ @app.post('/api/v1/text/generate')
124
+ async def text_generate(request: Request):
125
+ data = await request.json()
126
+ messages = data['messages']
127
+ choice = data['model']
128
+ api_key = data['api_key']
129
+
130
+ if api_key != "test123":
131
+ return {"error": "Invalid API key."}
132
+
133
+ if api_key not in data:
134
+ return {"error": "API key is required."}
135
+
136
+ if not messages or not model:
137
+ return {"error": "Invalid request. 'messages' and 'model' are required."}
138
+
139
+ model = FetchModel().select_model(choice)
140
+ if not model:
141
+ return {"error": f"Model '{choice}' is not supported."}
142
+
143
+ try:
144
+ query = {
145
+ 'model': model,
146
+ 'max_tokens': None,
147
+ 'temperature': 0.7,
148
+ 'top_p': 0.7,
149
+ 'top_k': 50,
150
+ 'repetition_penalty': 1,
151
+ 'stream_tokens': True,
152
+ 'stop': ['<|eot_id|>', '<|eom_id|>'],
153
+ 'messages': messages,
154
+ 'stream': True,
155
+ }
156
+
157
+ together_models = TogetherAPI().get_model_list()
158
+ xai_models = XaiAPI().get_model_list()
159
+ groq_models = GroqAPI().get_model_list()
160
+ deepinfra_models = DeepinfraAPI().get_model_list()
161
+
162
+ if model in together_models:
163
+ streamModel = TogetherAPI()
164
+ elif model in xai_models:
165
+ streamModel = XaiAPI()
166
+ elif model in groq_models:
167
+ streamModel = GroqAPI()
168
+ elif model in deepinfra_models:
169
+ streamModel = DeepinfraAPI()
170
+ else:
171
+ return {"error": f"Model '{model}' is not supported."}
172
+
173
+ response = streamModel.generate(query)
174
+
175
+ return StreamingResponse(response, media_type="text/event-stream")
176
+
177
  except Exception as e:
178
  return {"error": f"An error occurred: {str(e)}"}
models/.DS_Store CHANGED
Binary files a/models/.DS_Store and b/models/.DS_Store differ
 
models/__pycache__/fetch.cpython-311.pyc ADDED
Binary file (4.84 kB). View file
 
models/fetch.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+
3
+ class FetchModel:
4
+
5
+ @staticmethod
6
+ def all_models():
7
+
8
+ models = [
9
+ {
10
+ "id": "llama-4-maverick-17b",
11
+ "name": "LLaMA 4 Maverick 17B",
12
+ "description": "Meta AI's 17B-parameter general-purpose model from the LLaMA 4 series, designed for high-quality text generation.",
13
+ "type": "text"
14
+ },
15
+ {
16
+ "id": "llama-4-scout-17b",
17
+ "name": "LLaMA 4 Scout 17B",
18
+ "description": "Instruction-tuned version of LLaMA 4 by Meta, tailored for alignment and structured task performance.",
19
+ "type": "text"
20
+ },
21
+ {
22
+ "id": "llama-3.1-8b",
23
+ "name": "LLaMA 3.1 8B",
24
+ "description": "A fast and lightweight 8B parameter model from Meta's LLaMA 3.1 line, optimized for low-latency inference.",
25
+ "type": "text"
26
+ },
27
+ {
28
+ "id": "llama-3.3-70b",
29
+ "name": "LLaMA 3.3 70B",
30
+ "description": "Meta's 70B parameter flagship model from LLaMA 3.3, designed for state-of-the-art language understanding and generation.",
31
+ "type": "text"
32
+ },
33
+ {
34
+ "id": "deepseek-r1",
35
+ "name": "DeepSeek R1",
36
+ "description": "DeepSeek AIs foundational model focused on reasoning, language understanding, and long-context comprehension.",
37
+ "type": "text"
38
+ },
39
+ {
40
+ "id": "deepseek-v3",
41
+ "name": "DeepSeek V3",
42
+ "description": "DeepSeek AIs third-generation model with enhanced reasoning and coding abilities.",
43
+ "type": "text"
44
+ },
45
+ {
46
+ "id": "qwen-2.5-72b",
47
+ "name": "Qwen 2.5 72B",
48
+ "description": "Large instruction-tuned language model from Qwen 2.5 family, optimized for complex NLP tasks.",
49
+ "type": "text"
50
+ },
51
+ {
52
+ "id": "gemma-2-27b",
53
+ "name": "Gemma 2 27B",
54
+ "description": "Googles instruction-tuned model with 27B parameters, capable of high-performance natural language understanding.",
55
+ "type": "text"
56
+ },
57
+ {
58
+ "id": "grok-3",
59
+ "name": "Grok 3",
60
+ "description": "xAI's general-purpose large language model designed for reasoning, conversation, and alignment.",
61
+ "type": "text"
62
+ },
63
+ {
64
+ "id": "grok-3-fast",
65
+ "name": "Grok 3 (Fast)",
66
+ "description": "A low-latency version of Grok 3 optimized for responsiveness and quick task execution.",
67
+ "type": "text"
68
+ },
69
+ {
70
+ "id": "grok-3-mini",
71
+ "name": "Grok 3 Mini",
72
+ "description": "A smaller variant of Grok 3 designed for lighter inference while maintaining core capabilities.",
73
+ "type": "text"
74
+ },
75
+ {
76
+ "id": "grok-3-mini-fast",
77
+ "name": "Grok 3 Mini (Fast)",
78
+ "description": "Fast and lightweight variant of Grok 3 Mini for extremely low-latency use cases.",
79
+ "type": "text"
80
+ },
81
+ {
82
+ "id": "grok-2-1212",
83
+ "name": "Grok 2 1212",
84
+ "description": "An earlier generation Grok model from xAI, optimized for general language tasks with improved efficiency.",
85
+ "type": "text"
86
+ }
87
+ ]
88
+
89
+ return models
90
+
91
+ async def select_model(id):
92
+ if id == "llama-4-maverick-17b":
93
+ options = ['meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8']
94
+ model = random.choice(options)
95
+ return model
96
+ elif id == "llama-4-scout-17b":
97
+ options = ['meta-llama/Llama-4-Scout-17B-16E-Instruct', 'meta-llama/llama-4-scout-17b-16e-instruct']
98
+ model = random.choice(options)
99
+ return model
100
+ elif id == "llama-3.1-8b":
101
+ options = ['llama-3.1-8b-instant']
102
+ model = random.choice(options)
103
+ return model
104
+ elif id == "llama-3.3-70b":
105
+ options = ['meta-llama/Llama-3.3-70B-Instruct-Turbo', 'llama-3.3-70b-versatile']
106
+ model = random.choice(options)
107
+ return model
108
+ elif id == "deepseek-r1":
109
+ options = ['deepseek-ai/DeepSeek-R1', 'deepseek-r1-distill-llama-70b']
110
+ model = random.choice(options)
111
+ return model
112
+ elif id == "deepseek-v3":
113
+ options = ['deepseek-ai/DeepSeek-V3']
114
+ model = random.choice(options)
115
+ return model
116
+ elif id == "qwen-2.5-72b":
117
+ options = ['Qwen/Qwen2.5-VL-72B-Instruct', 'Qwen/Qwen2.5-72B-Instruct']
118
+ model = random.choice(options)
119
+ return model
120
+ elif id == "gemma-2-27b":
121
+ options = ['google/gemma-2-27b-it']
122
+ model = random.choice(options)
123
+ return model
124
+ elif id == "grok-3":
125
+ options = ['grok-3']
126
+ model = random.choice(options)
127
+ return model
128
+ elif id == "grok-3-fast":
129
+ options = ['grok-3-fast']
130
+ model = random.choice(options)
131
+ return model
132
+ elif id == "grok-3-mini":
133
+ options = ['grok-3-mini']
134
+ model = random.choice(options)
135
+ return model
136
+ elif id == "grok-3-mini-fast":
137
+ options = ['grok-3-mini-fast']
138
+ model = random.choice(options)
139
+ return model
140
+ elif id == "grok-2-1212":
141
+ options = ['grok-2-1212']
142
+ model = random.choice(options)
143
+ return model
144
+
145
+
models/image/together/__pycache__/main.cpython-311.pyc ADDED
Binary file (3.06 kB). View file
 
models/image/vercel/__pycache__/main.cpython-311.pyc ADDED
Binary file (2.65 kB). View file
 
models/text/.DS_Store CHANGED
Binary files a/models/text/.DS_Store and b/models/text/.DS_Store differ
 
models/text/together/__pycache__/main.cpython-311.pyc ADDED
Binary file (6.49 kB). View file
 
models/text/vercel/__pycache__/main.cpython-311.pyc ADDED
Binary file (16.2 kB). View file
 
test.py CHANGED
@@ -1,47 +1,47 @@
1
- # import requests
2
- # import json
3
-
4
- # messages = [
5
- # {"role": "user", "content": "helo"},
6
- # {"role": "assistant", "content": "Hello! How can I assist you today?"},
7
- # {"role": "user", "content": "who are you and give me a breif description of who created you "}
8
- # ]
9
-
10
- # model = "Qwen/Qwen2.5-72B-Instruct"
11
-
12
- # url = " http://127.0.0.1:8000/api/v1/generate"
13
-
14
- # payload = {
15
- # "messages": messages,
16
- # "model": model
17
- # }
18
-
19
- # response = requests.post(url, json=payload, stream=True)
20
-
21
- # if response.status_code == 200:
22
- # for line in response.iter_lines():
23
- # if line:
24
- # decoded_line = line.decode('utf-8')
25
- # if decoded_line.startswith('data: [DONE]'):
26
- # break
27
- # elif decoded_line.startswith('data: '):
28
- # try:
29
- # json_data = json.loads(decoded_line[6:])
30
- # if json_data["choices"] and "text" in json_data["choices"][0]:
31
- # print(json_data["choices"][0]["text"], end='')
32
- # except json.JSONDecodeError:
33
- # continue
34
- # else:
35
- # print(f"Request failed with status code {response.status_code}")
36
 
37
 
38
  import requests
39
 
40
- url = 'http://127.0.1:8000/api/v1/generate-images'
41
 
42
  query = {
43
  'prompt': 'a beautiful landscape',
44
- 'model': 'black-forest-labs/FLUX.1-dev',
45
  }
46
 
47
  response = requests.post(url, json=query)
 
1
+ import requests
2
+ import json
3
+
4
+ messages = [
5
+ {"role": "user", "content": "helo"},
6
+ {"role": "assistant", "content": "Hello! How can I assist you today?"},
7
+ {"role": "user", "content": "who are you and give me a breif description of who created you "}
8
+ ]
9
+
10
+ model = "Qwen/Qwen2.5-72B-Instruct"
11
+
12
+ url = "https://chipling-api.hf.space/api/v1/generate"
13
+
14
+ payload = {
15
+ "messages": messages,
16
+ "model": model
17
+ }
18
+
19
+ response = requests.post(url, json=payload, stream=True)
20
+
21
+ if response.status_code == 200:
22
+ for line in response.iter_lines():
23
+ if line:
24
+ decoded_line = line.decode('utf-8')
25
+ if decoded_line.startswith('data: [DONE]'):
26
+ break
27
+ elif decoded_line.startswith('data: '):
28
+ try:
29
+ json_data = json.loads(decoded_line[6:])
30
+ if json_data["choices"] and "text" in json_data["choices"][0]:
31
+ print(json_data["choices"][0]["text"], end='')
32
+ except json.JSONDecodeError:
33
+ continue
34
+ else:
35
+ print(f"Request failed with status code {response.status_code}")
36
 
37
 
38
  import requests
39
 
40
+ url = 'https://chipling-api.hf.space/api/v1/generate-images'
41
 
42
  query = {
43
  'prompt': 'a beautiful landscape',
44
+ 'model': 'fal-ai/fast-sdxl',
45
  }
46
 
47
  response = requests.post(url, json=query)