File size: 14,022 Bytes
177e4c2
 
 
 
 
 
 
 
 
 
 
 
97339e2
177e4c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3738fa
177e4c2
 
 
 
 
 
 
9451027
 
e3738fa
 
 
24c061e
e3738fa
 
 
 
 
 
 
 
9451027
 
 
 
06d209a
 
 
 
7028d44
 
 
 
8fb760a
df8d0a4
 
 
a37a647
 
 
df8d0a4
 
4d70c71
 
 
5799683
 
 
 
2366656
 
 
 
c0b9fec
 
 
 
 
31585bb
 
2366656
31585bb
f6874c9
 
 
 
3655a2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177e4c2
 
 
f6874c9
 
899e654
 
 
f6874c9
 
 
97339e2
 
 
 
177e4c2
97339e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3738fa
97339e2
 
 
177e4c2
97339e2
 
177e4c2
97339e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177e4c2
97339e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177e4c2
97339e2
 
 
 
 
 
 
 
 
177e4c2
97339e2
 
177e4c2
97339e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3738fa
97339e2
e3738fa
177e4c2
3655a2f
 
24c061e
3655a2f
24c061e
3655a2f
 
177e4c2
 
 
97339e2
177e4c2
 
2366656
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>Quardo's OpenAI proxy</title>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="description" content="Quardo's OpenAI proxy documentation">
		<meta name="keywords" content="OpenAI, proxy, API, documentation, GPT-4O-mini">
		<meta name="author" content="Quardo">
		<meta property="og:title" content="Quardo's OpenAI proxy">
		<meta property="og:description" content="Documentation for Quardo's OpenAI proxy">
		<meta property="og:type" content="website">
		<meta property="og:url" content="https://https://quardo-gpt-4o-mini.hf.space/api/v1/docs">
		<meta property="og:image" content="https://tenor.com/view/cat-cat-e-cat-meme-cat-face-gif-23642589">
		<meta name="twitter:card" content="summary_large_image">
		<meta name="twitter:title" content="Quardo's OpenAI proxy">
		<meta name="twitter:description" content="Documentation for Quardo's OpenAI proxy">
		<meta name="twitter:image" content="https://tenor.com/view/cat-cat-e-cat-meme-cat-face-gif-23642589">
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.css">
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/theme/monokai.min.css">
		<style>
			body {font-family: Arial, sans-serif; background-color: #f4f4f9; color: #333; margin: 0; padding: 0;}
			h1, h2 {color: #444; text-align: center;}
			.main {max-width: 800px; margin: 20px auto; padding: 20px; background-color: #fff; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); border-radius: 8px;}
			.CodeMirror {border: 1px solid #ddd; border-radius: 8px; margin: 20px 0;}
			hr {border: 0; height: 1px; background: #ddd; margin: 40px 0;}
			p {line-height: 1.6;}
		</style>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/python/python.min.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/javascript/javascript.min.js"></script>
	</head>
	<body>
		<div class="main">
			<hr/>
			<h1>Documentation of the API/updates</h1>
			<hr/>
			<h2>Updates</h2>
			<button onclick="if (updates.style.display === 'none') { updates.style.display = 'block'; } else { updates.style.display = 'none'; }">Show/Hide updates</button>
			<div style="display: none;" id="updates">
				<div>
					<strong> - 13. Update.</strong>
					<p> * New API endpoint.</p>
					<p> - To get an API key you can login at <a href="https://cow.rip/api/v1/oauth/hf">Here!</a></p>
					<p> - Note: any key found on anywhere on the internet will get force-reset</p>
				</div><hr/>
				<div>
					<strong> - 12. Update.</strong>
					<p> * Updated faketool [search].</p>
					<p> - on performance (30s => 22~s) by switching search API.</p>
					<p> - on knowledge (better scraping).</p>
				</div><hr/>
				<div>
					<strong> - 11. Update.</strong>
					<p> * Finally found out a better way for TOS acception.</p>
				</div><hr/>
				<div>
					<strong> - 10. Update.</strong>
					<p> * Added OpenAI's new response param "refusal".</p>
				</div><hr/>
				<div>
					<strong> - 9. Update.</strong>
					<p> * Added a third faketool: search. Now the model can search, via search engine.</p>
				</div><hr/>
				<div>
					<div>
						<strong> - 8. Update.</strong>
						<p> * Got new hosting for this space; <a href="https://chat.cow.rip/">chat.cow.rip</a></p>
							<label>- The new hosting is provided by: repl.it.</label><br/>
							<label>- The updates to the space will first be released there,</label><br/>
							<label>- then later, they will come to the Hugging Face space, mostly due to the fact that repl.it is capable of faster build speeds.</label><br/>
							<label>- So in simple terms, <a href="https://chat.cow.rip/">chat.cow.rip</a> will be like a beta release for this space, and that's it.</label>
					</div><hr/>
					<strong> - 7. Update.</strong>
					<p> * Added a second faketool: math. Now the model can perform calculations.</p>
				</div><hr/>
				<div>
					<strong> - 6. Update.</strong>
					<p> * Added image generation via DALL-E-3.</p>
				</div><hr/>
				<div>
					<strong> - 5. Update Rollback (part 2).</strong>
					<p> * Switched back to old model, as it at least did some enough check</p>
				</div><hr/>
				<div>
					<strong> - 5. Update Rollback.</strong>
					<p> * After just a day, the new moderation turns out to be <strong>*extreamly*</strong> strict, so moderation has been paused until i found a better way.</p>
						<label>- By to *strict* i meant as blocking pretty much everything, unless it is something like 'Hello.'</label>
				</div><hr/>
				<div>
					<strong> - 5. Update.</strong>
					<p> * Added extreamly strict moderation.</p>
				</div><hr/>
				<div>
					<strong> - 4. Update.</strong>
					<p> * Added a user consent feature for the application's terms of use.</p>
				</div><hr/>
				<div>
					<strong> - 3. Update.</strong>
					<p> * Managed to fix the file being non-visible to the AI model after one round.</p>
					<p> * And fix the div error on this page.</p>
				</div><hr/>
				<div>
					<strong> - 2. Update.</strong>
					<p> * Added light moderation. [Might add more strict detection later]</p>
				</div><hr/>
				<div>
					<strong> - 1. Update.</strong>
					<p> * Fixed a bug where file encoding could trash the entire chat.</p>
					<p> * Made models allowed set by the maintainer. [OPENAI_API_MODELS variable]</p>
				</div><hr/>
				<div>
					<p><strong id="w" alt="yes i love fear"> * </strong>yippeeee</p>
					<script>let q=25;setInterval(_=>{q+=.001;w.style.fontSize=`${q}px`},100);</script>
					<label style="font-size: 2px;">The message above is edited by a script every 100ms. you can check it via view-source.</label>
				</div>
			</div>
			<hr/>
			<h2>API Endpoints</h2>
			<p>Here are some example codes to interact with the API:</p>
			<p><strong>Note:</strong> By using our API, you acknowledge and agree to the following terms regarding the data you provide:</p>
			<ul>
				<li>Data Collection: This application may log the following data through the Gradio endpoint or the API endpoint: message requests (including messages, responses, model settings, and images sent along with the messages), images that were generated (including only the prompt and the image), search tool calls (including query, search results, summaries, and output responses), and moderation checks (including input and output).</li>
				<li>Data Retention and Removal: Data is retained until further notice or until a specific request for removal is made.</li>
				<li>Data Usage: The collected data may be used for various purposes, including but not limited to, administrative review of logs, AI training, and publication as a dataset.</li>
				<li>Privacy: Please avoid sharing any personal information.</li>
			</ul>
			<p>By continuing to use our API, you explicitly consent to the collection, use, and potential sharing of your data as described above. If you disagree with our data collection, usage, and sharing practices, we advise you not to use our API.</p>
			<textarea id="example1" name="example1"># For Python3:
import asyncio
import aiohttp
import json

base_url = "https://cow.rip/api/v1"
key = "sk-quardo-..."  # You can get a key by logging in at https://cow.rip/api/v1/oauth/hf
params = {
	# Model to use for the chat. You can view the models at https://cow.rip/api/v1/models in your browser
	'model': "gpt-4o-mini",
	
	# List of messages to send to the API. Each message should be a dictionary with 'role' and 'content'.
	'messages': [
		{'role': 'user', 'content': 'Hello!'}
	],
	
	# Boolean to enable or disable streaming of the response.
	'stream': True
	
	# For any other paramater please take a look at https://platform.openai.com/docs/api-reference/chat
}

async def chat(params):
	"""
	Function to interact with the chat API.

	Args:
		params (dict): Parameters to be sent to the API. Must include 'model', 'messages', and optionally any other paramaters that OpenAI supports (https://platform.openai.com/docs/api-reference/chat).

	Yields:
		str: The content of the response message from the API.
	"""
	async with aiohttp.ClientSession() as session:
		async with session.post(
			f'{base_url}/chat/completions',
			headers={
				'Content-Type': 'application/json',
				'Authorization': f'Bearer {key}'
			},
			json=params,
			timeout=10  # Timeout for the request in seconds
		) as response:
			# Check if the response has a content body
			if not response.content:
				raise Exception('No response body received')

			# If streaming is enabled, process the response line by line
			if params.get('stream', False):
				async for line in response.content:
					data = line.decode('utf-8').strip()
					if data.startswith("data: ") and (msg := data[6:]) != "[DONE]":
						try:
							parsed = json.loads(msg)
							if 'choices' in parsed:
								choice = parsed['choices'][0]
								if 'delta' in choice and 'content' in choice['delta']:
									yield choice['delta']['content']
						except json.JSONDecodeError as e:
							print(f"Failed to parse JSON event: {e}")
			else:
				# If streaming is not enabled, process the entire response at once
				result = await response.json()
				if 'choices' in result:
					choice = result['choices'][0]
					if 'message' in choice:
						yield choice['message']['content']
					else:
						yield "{Invalid response received}"
				else:
					yield "{Invalid response received}"

async def main():
	"""
	Main function to initiate the chat interaction.

	This function sets up the parameters for the chat API call and processes the response.
	"""
	async for msg in chat(params):
		print(msg, end="", flush=True)
	print()

if __name__ == "__main__":
	asyncio.run(main())</textarea>
			<hr/>
			<textarea id="example2" name="example2">// For Node.JS:
				const baseUrl = "https://cow.rip/api/v1";
const key = "sk-quardo-...";  // You can get a key by logging in at https://cow.rip/api/v1/oauth/hf
const params = {
    // Model to use for the chat. You can view the models at https://cow.rip/api/v1/models in your browser or use the models() function.
    model: "gpt-4o-mini",
    
    // List of messages to send to the API. Each message should be a dictionary with 'role' and 'content'.
    messages: [
        { role: "user", content: "Hello!" }
    ],
    
    // Boolean to enable or disable streaming of the response.
    stream: true
    
    // For any other parameter please take a look at https://platform.openai.com/docs/api-reference/chat
};

/**
 * Function to interact with the chat API.
 *
 * @param {Object} params - Parameters to be sent to the API. Must include 'model', 'messages', and optionally any other paramaters that OpenAI supports (https://platform.openai.com/docs/api-reference/chat).
 * @yields {string} - The content of the response message from the API.
 */
async function* chat(params) {
    const response = await fetch(`${baseUrl}/chat/completions`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${key}`
        },
        body: JSON.stringify(params)
    });

    if (!response.body) {
        throw new Error('No response body received');
    }

    if (params.stream) {
        const reader = response.body.getReader();
        let done, value, buffer = '';

        while (!done) {
            ({ value, done } = await reader.read());
            if (value) {
                buffer += new TextDecoder().decode(value);
                let boundaryIndex;
                while ((boundaryIndex = buffer.indexOf("\n\n")) !== -1) {
                    const chunk = buffer.slice(0, boundaryIndex + 2);
                    buffer = buffer.slice(boundaryIndex + 2);
                    if (chunk.trim().startsWith("data: ")) {
                        const data = chunk.substring(6).trim();
                        if (data !== "[DONE]") {
                            try {
                                const parsed = JSON.parse(data);
                                if (parsed.choices && parsed.choices[0] && parsed.choices[0].delta) {
                                    yield parsed.choices[0].delta.content || "";
                                }
                            } catch (e) {
                                console.error(`Failed to parse JSON event: ${e.message}`);
                            }
                        }
                    }
                }
            }
        }
    } else {
        const result = await response.json();
        if (result.choices && result.choices[0] && result.choices[0].message) {
            yield result.choices[0].message.content || "{Invalid response received}";
        } else {
            yield "{Invalid response received}";
        }
    }
}

/**
 * Main function to initiate the chat interaction.
 *
 * This function sets up the parameters for the chat API call and processes the response.
 */
async function main() {
    for await (const msg of chat(params)) {
        process.stdout.write(msg);
    }
    process.stdout.write("\n");
}

main().catch(console.error);
</textarea>
			<hr/>
			<div>
				<h3>Actual endpoints:</h3>
				<p><strong>1. [GET]</strong> <a href="https://cow.rip/api/v1/models">/api/v1/models</a></p>
					<label>Simply shows you the available models</label>
				<p><strong>3. [POST]</strong> <a href="https://cow.rip/api/v1/chat/completions">/api/v1/chat/completions</a></p>
					<label>Generates a chat completion based on the provided messages and model</label>
			</div>
		</div>
		<script>
			CodeMirror.fromTextArea(document.getElementById("example1"), { lineNumbers: true, mode: "python", theme: "monokai", readOnly: true });
			CodeMirror.fromTextArea(document.getElementById("example2"), { lineNumbers: true, mode: "javascript",  theme: "monokai", readOnly: true });
		</script>
	</body>
</html>