11import base64
22import os
3- import typing
43from time import sleep
54from uuid import uuid4
65
7- try :
8- import pydantic .v1 as pydantic # type: ignore
9- except ImportError :
10- import pydantic # type: ignore
11-
126from langfuse .api import LangfuseAPI
137
148
@@ -26,62 +20,6 @@ def get_api():
2620 )
2721
2822
29- class LlmUsageWithCost (pydantic .BaseModel ):
30- prompt_tokens : typing .Optional [int ] = pydantic .Field (
31- alias = "promptTokens" , default = None
32- )
33- completion_tokens : typing .Optional [int ] = pydantic .Field (
34- alias = "completionTokens" , default = None
35- )
36- total_tokens : typing .Optional [int ] = pydantic .Field (
37- alias = "totalTokens" , default = None
38- )
39- input_cost : typing .Optional [float ] = pydantic .Field (alias = "inputCost" , default = None )
40- output_cost : typing .Optional [float ] = pydantic .Field (
41- alias = "outputCost" , default = None
42- )
43- total_cost : typing .Optional [float ] = pydantic .Field (alias = "totalCost" , default = None )
44-
45-
46- class CompletionUsage (pydantic .BaseModel ):
47- completion_tokens : int
48- """Number of tokens in the generated completion."""
49-
50- prompt_tokens : int
51- """Number of tokens in the prompt."""
52-
53- total_tokens : int
54- """Total number of tokens used in the request (prompt + completion)."""
55-
56-
57- class LlmUsage (pydantic .BaseModel ):
58- prompt_tokens : typing .Optional [int ] = pydantic .Field (
59- alias = "promptTokens" , default = None
60- )
61- completion_tokens : typing .Optional [int ] = pydantic .Field (
62- alias = "completionTokens" , default = None
63- )
64- total_tokens : typing .Optional [int ] = pydantic .Field (
65- alias = "totalTokens" , default = None
66- )
67-
68- def json (self , ** kwargs : typing .Any ) -> str :
69- kwargs_with_defaults : typing .Any = {
70- "by_alias" : True ,
71- "exclude_unset" : True ,
72- ** kwargs ,
73- }
74- return super ().json (** kwargs_with_defaults )
75-
76- def dict (self , ** kwargs : typing .Any ) -> typing .Dict [str , typing .Any ]:
77- kwargs_with_defaults : typing .Any = {
78- "by_alias" : True ,
79- "exclude_unset" : True ,
80- ** kwargs ,
81- }
82- return super ().dict (** kwargs_with_defaults )
83-
84-
8523def encode_file_to_base64 (image_path ) -> str :
8624 with open (image_path , "rb" ) as file :
8725 return base64 .b64encode (file .read ()).decode ("utf-8" )
0 commit comments