gpt-4o-mini / index.html
Quardo's picture
Updated space.
97339e2
raw
history blame contribute delete
No virus
14 kB
<!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>