def analyze_screenshot_base64(encoded_image): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {openai.api_key}" } payload = { "model": "gpt-4o-mini", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Develop a trading setup (LONG or SHORT) with a CRV of at least 5 based on this chart. Include entry price, stop loss, and take profit levels." }, { "type": "image_url", "image": { "url": f"data:image/png;base64,{encoded_image}" } } ] } ], "max_tokens": 300 } response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload) return response.json() Python def analyze_screenshot_base64(encoded_image): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {openai.api_key}" } payload = { "model": "gpt-4o-mini", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Develop a trading setup (LONG or SHORT) with a CRV of at least 5 based on this chart. Include entry price, stop loss, and take profit levels." }, { "type": "image_url", "image": { "url": f"data:image/png;base64,{encoded_image}" } } ] } ], "max_tokens": 300 } response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload) return response.json() Мне нужно сделать такой же POST запрос, но для отправки файла на расшифровку, и не нужно мне показывать библиотеку openai и другие, только requests. Мне параметры в payload нужно верно расставить, а у меня не получается, нашёл только для изображения, а для файла нет.
Dima6282669 import requests def analyze_file(file_path): headers = { "Authorization": f"Bearer {your_api_key}" } with open(file_path, 'rb') as file: files = { 'file': file } # Дополнительные параметры для запроса data = { "model": "gpt-4o-mini", "max_tokens": 300, "purpose": "fine-tune" # или другой параметр, если требуется } # Отправляем POST-запрос response = requests.post("https://api.openai.com/v1/files", headers=headers, files=files, data=data) return response.json() Python import requests def analyze_file(file_path): headers = { "Authorization": f"Bearer {your_api_key}" } with open(file_path, 'rb') as file: files = { 'file': file } # Дополнительные параметры для запроса data = { "model": "gpt-4o-mini", "max_tokens": 300, "purpose": "fine-tune" # или другой параметр, если требуется } # Отправляем POST-запрос response = requests.post("https://api.openai.com/v1/files", headers=headers, files=files, data=data) return response.json()
Привет, Mnogkco! Давай попробуем разобраться с отправкой файла через POST запрос с использованием библиотеки `requests`. Если ты хочешь отправить файл, то тебе нужно использовать параметр `files` в функции `requests.post`. Вот пример, как это можно сделать: import requests def send_file_for_processing(file_path): url = "https://your-api-endpoint.com/process-file" headers = { "Authorization": "Bearer YOUR_ACCESS_TOKEN" } with open(file_path, 'rb') as file: files = { 'file': file } response = requests.post(url, headers=headers, files=files) return response.json() # Пример использования response = send_file_for_processing("path/to/your/file.txt") print(response) Python import requests def send_file_for_processing(file_path): url = "https://your-api-endpoint.com/process-file" headers = { "Authorization": "Bearer YOUR_ACCESS_TOKEN" } with open(file_path, 'rb') as file: files = { 'file': file } response = requests.post(url, headers=headers, files=files) return response.json() # Пример использования response = send_file_for_processing("path/to/your/file.txt") print(response) В этом примере файл отправляется на сервер, и ты получаешь ответ в формате JSON. Не забудь заменить `"https://your-api-endpoint.com/process-file"` на реальный URL, куда ты отправляешь запрос, и `"YOUR_ACCESS_TOKEN"` на твой токен доступа, если он требуется. Если у тебя есть дополнительные параметры, которые нужно передать в запросе, их можно добавить в параметр `data` или `json` в зависимости от требований API.
from openai import OpenAI client = OpenAI() file = client.files.create( file=open("file.pdf", "rb"), purpose="fine-tune" ) client = OpenAI() completion = client.chat.completions.create( model="gpt-4-1106", messages=[ {"role": "system", "content": "You are a helpful assistant that can read PDFs."}, {"role": "user", "content": f"Extract the text from the 3rd page from {file.id}"} ] ) print(completion.choices[0].message) Python from openai import OpenAI client = OpenAI() file = client.files.create( file=open("file.pdf", "rb"), purpose="fine-tune" ) client = OpenAI() completion = client.chat.completions.create( model="gpt-4-1106", messages=[ {"role": "system", "content": "You are a helpful assistant that can read PDFs."}, {"role": "user", "content": f"Extract the text from the 3rd page from {file.id}"} ] ) print(completion.choices[0].message) Идешь в либу, копируешь код