Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // venice.js
- const fetch = require("node-fetch")
- async function chatVeniceAI(prompt, modelId = "zai-org-glm-4.6") {
- const url = 'https://outerface.venice.ai/api/inference/chat';
- const timestamp = new Date().toISOString().slice(0, 19) + '+08:00';
- const requestId = Math.random().toString(36).substring(2, 10);
- const conversationId = Math.random().toString(36).substring(2, 10).toUpperCase();
- const data = {
- conversationId: conversationId,
- characterId: "",
- clientProcessingTime: 1618,
- conversationType: "text",
- includeVeniceSystemPrompt: true,
- isCharacter: false,
- modelId: modelId,
- prompt: [{
- content: prompt,
- role: "user"
- }],
- reasoning: false,
- requestId: requestId,
- systemPrompt: "",
- temperature: 0.7,
- topP: 0.9,
- userId: "user_anon_1234568910",
- webEnabled: true,
- webScrapeEnabled: false
- };
- const headers = {
- 'Host': 'outerface.venice.ai',
- 'sec-ch-ua': '"Chromium";v="139", "Not;A=Brand";v="99"',
- 'x-venice-locale': 'en',
- 'sec-ch-ua-mobile': '?1',
- 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Mobile Safari/537.36',
- 'content-type': 'application/json',
- 'x-venice-timestamp': timestamp,
- 'sec-ch-ua-platform': '"Android"',
- 'accept': '*/*',
- 'origin': 'https://venice.ai',
- 'sec-fetch-site': 'same-site',
- 'sec-fetch-mode': 'cors',
- 'sec-fetch-dest': 'empty',
- 'referer': 'https://venice.ai/',
- 'accept-encoding': 'gzip, deflate, br',
- 'accept-language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7'
- };
- const response = await fetch(url, {
- method: 'POST',
- headers: headers,
- body: JSON.stringify(data)
- });
- if (!response.ok) {
- const errorText = await response.text();
- throw new Error(`HTTP ${response.status}: ${errorText}`);
- }
- const reader = response.body.getReader();
- const decoder = new TextDecoder();
- let fullResponse = '';
- while (true) {
- const { done, value } = await reader.read();
- if (done) break;
- const chunk = decoder.decode(value);
- const lines = chunk.split('\n');
- for (const line of lines) {
- if (line.trim()) {
- try {
- const data = JSON.parse(line);
- if (data.kind === 'content' && data.content) {
- fullResponse += data.content;
- }
- } catch (e) {
- continue;
- }
- }
- }
- }
- return { success: true, response: fullResponse };
- }
Advertisement
Add Comment
Please, Sign In to add comment