Skip to content

Commit

Permalink
feat: Add image processing functionality to OpenAIClient
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseFredes committed Aug 24, 2024
1 parent 3b7387d commit 85aadd0
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions openAI/client.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
import openai
import openai.resources

from utils.images import encode_image

class OpenAIClient:
def __init__(self, api_key):
self.api_key = api_key
openai.api_key = self.api_key


def create_completion(self, prompt, model="gpt-4o-mini", max_tokens=50):
print(model)
print(prompt)
print(max_tokens)

print(chat_completion.choices)
chat_completion = openai.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}],
)
message_content = chat_completion.choices[0].message.content
print(message_content)
return chat_completion
return message_content

def process_image(self):
image_path = './images/puño.jpeg'
base64_image = encode_image(image_path)
response = openai.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "En una imagen donde se muestra una mano con los dedos extendidos, ¿qué movimiento esperas que haga la mano? Si la mano se cierra, devuelve 1. Si la mano se abre, devuelve 0. Si es un movimiento de pinzas, devuelve 2."},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{base64_image}",
},
},
],
}
],
max_tokens=300,
)
return response.choices[0].message.content

0 comments on commit 85aadd0

Please sign in to comment.