44import toml
55from pathlib import Path
66
7- from .utils import split_image_uri , Config
7+ from .utils import split_image_uri , ensure_image_uri , Config
88
99##
1010## authorization headers
@@ -17,7 +17,7 @@ def authorize_openai(api_key):
1717
1818def authorize_anthropic (api_key ):
1919 return {
20- 'x-api-key ' : api_key ,
20+ 'X-Api-Key ' : api_key ,
2121 }
2222
2323##
@@ -27,7 +27,7 @@ def authorize_anthropic(api_key):
2727def content_openai (text , image = None ):
2828 if image is None :
2929 return text
30- image_url = { 'url' : image }
30+ image_url = { 'url' : ensure_image_uri ( image ) }
3131 return [
3232 { 'type' : 'image_url' , 'image_url' : image_url },
3333 { 'type' : 'text' , 'text' : text },
@@ -36,7 +36,8 @@ def content_openai(text, image=None):
3636def content_anthropic (text , image = None ):
3737 if image is None :
3838 return text
39- media_type , data = split_image_uri (image )
39+ image_url = ensure_image_uri (image )
40+ media_type , data = split_image_uri (image_url )
4041 source = {
4142 'type' : 'base64' , 'media_type' : media_type , 'data' : data
4243 }
@@ -174,6 +175,11 @@ def embed_response_openai(reply):
174175 item ['embedding' ] for item in reply ['data' ]
175176 ]
176177
178+ def embed_response_openai_native (reply ):
179+ return [
180+ item .embedding for item in reply .data
181+ ]
182+
177183def embed_payload_tei (text ):
178184 return {'inputs' : text }
179185
@@ -264,22 +270,18 @@ def transcribe_response_openai(audio):
264270## known llm providers
265271##
266272
267- # get config paths
268- library_dir = Path (__file__ ).parent
269- xdg_config_home = Path (os .environ .get ('XDG_CONFIG_HOME' , os .path .expanduser ('~/.config' )))
270- user_config_dir = xdg_config_home / 'oneping'
271- default_providers_file = library_dir / 'providers.toml'
272- user_providers_file = user_config_dir / 'providers.toml'
273- default_config_file = library_dir / 'config.toml'
274- user_config_file = user_config_dir / 'config.toml'
275-
276273# fault tolerant toml loader
277274def load_toml (file ):
278275 if os .path .exists (file ):
279276 return toml .load (file )
280277 else :
281278 return {}
282279
280+ # get config paths
281+ XDG_LOC = os .path .expanduser ('~/.config' )
282+ LIB_DIR = Path (__file__ ).parent
283+ XDG_DIR = Path (os .environ .get ('XDG_CONFIG_HOME' , XDG_LOC ))
284+
283285# merge config layers
284286global PROVIDERS
285287global CONFIG
@@ -288,10 +290,10 @@ def reload():
288290 global CONFIG
289291
290292 # reload config from disk
291- DEFAULT_CONFIG = load_toml (default_config_file )
292- USER_CONFIG = load_toml (user_config_file )
293- DEFAULT_PROVIDERS = load_toml (default_providers_file )
294- USER_PROVIDERS = load_toml (user_providers_file )
293+ DEFAULT_CONFIG = load_toml (LIB_DIR / 'config.toml' )
294+ DEFAULT_PROVIDERS = load_toml (LIB_DIR / 'providers.toml' )
295+ USER_CONFIG = load_toml (XDG_DIR / 'oneping' / 'config.toml' )
296+ USER_PROVIDERS = load_toml (XDG_DIR / 'oneping' / 'providers.toml' )
295297
296298 # merge provider layers
297299 CONFIG = Config ({ ** DEFAULT_CONFIG , ** USER_CONFIG })
0 commit comments