need helps converting python code to javascript
- User
need helps converting python code to javascript
- Assistant
Sure! I'd be happy to help you convert Python code to JavaScript. Please provide the Python code you'd like to convert, and I'll assist you with the translation.
- User
import requests, json
headers = { 'accept': '/', 'accept-language': 'en-US,en;q=0.9,id;q=0.8', 'content-type': 'application/json', 'origin': 'https://ai.pyjri.com', 'priority': 'u=1, i', 'referer': 'https://ai.pyjri.com/?model=%40cf%2Fmeta%2Fllama-3.1-8b-instruct', 'sec-ch-ua': '"Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Linux"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36', }
params = { 'stream': 'false', }
json_data = { 'model': '@cf/meta/llama-3.1-8b-instruct', 'prompt': 'hi there', 'system': '', 'stream': 'false', }
response = requests.post('https://ai.pyjri.com/api/generate', params=params, headers=headers, json=json_data)
responses = [] for r in response.text.splitlines(): data = json.loads(r)
if not data.get('done'): responses.append(data.get('response'))print(''.join([v for v in responses]))
- Assistant
- User
no, not nodejs. just pure javascript with fetch
- Assistant
Certainly! Below is the equivalent JavaScript code using the Fetch API that you can run directly in a browser (without Node.js):