11import httpx
2- import json
3- from embeddedllm .protocol import ChatCompletionRequest , ChatCompletionMessageParam , CustomChatCompletionMessageParam
2+
3+ from embeddedllm .protocol import (
4+ CustomChatCompletionMessageParam ,
5+ )
6+
47
58def chat_completion (url : str , payload : dict ):
69 with httpx .Client (timeout = None ) as client :
@@ -11,20 +14,24 @@ def chat_completion(url: str, payload: dict):
1114 print (f"Error: { response .status_code } " )
1215 print (response .text )
1316
17+
1418# Example usage
1519if __name__ == "__main__" :
16- IMAGE_PATH = "C: \\ Users \\ ryzz \\ VDrive \\ RyzenAI \\ icons8-amd-ryzen-64.png"
20+ import os
1721 import base64
1822 import mimetypes
1923
24+ current_file_path = os .path .abspath (__file__ )
25+ IMAGE_PATH = os .path .join (os .path .dirname (current_file_path ), ".." , "images" , "catdog.png" )
26+
2027 # Function to encode the image and infer its MIME type
2128 def encode_image (image_path ):
2229 mime_type , _ = mimetypes .guess_type (image_path )
2330 if mime_type is None :
2431 raise ValueError ("Could not infer the MIME type of the image." )
2532
2633 with open (image_path , "rb" ) as image_file :
27- base64_image = base64 .b64encode (image_file .read ()).decode (' utf-8' )
34+ base64_image = base64 .b64encode (image_file .read ()).decode (" utf-8" )
2835
2936 return mime_type , base64_image
3037
@@ -50,15 +57,15 @@ def encode_image(image_path):
5057 ],
5158 }
5259 ]
53-
60+
5461 payload = {
5562 "messages" : messages ,
5663 "model" : "phi3-mini-int4" ,
5764 "max_tokens" : 80 ,
5865 "temperature" : 0.0 ,
59- "stream" : False # Set stream to False
66+ "stream" : False , # Set stream to False
6067 }
6168 # print(data)
6269 # print(messages)
6370 # print(data.messages[0].content[0])
64- chat_completion (url , payload )
71+ chat_completion (url , payload )
0 commit comments