66
77import requests
88
9- from llama_stack .apis .inference import (
10- ChatCompletionRequest ,
11- JsonSchemaResponseFormat ,
12- ToolChoice ,
13- )
149from llama_stack .apis .models import Model
1510from llama_stack .log import get_logger
1611from llama_stack .providers .utils .inference .litellm_openai_mixin import LiteLLMOpenAIMixin
17- from llama_stack .providers .utils .inference .openai_compat import (
18- convert_message_to_openai_dict_new ,
19- convert_tooldef_to_openai_tool ,
20- get_sampling_options ,
21- )
2212
2313from .config import SambaNovaImplConfig
2414from .models import MODEL_ENTRIES
@@ -39,54 +29,10 @@ def __init__(self, config: SambaNovaImplConfig):
3929 api_key_from_config = self .config .api_key .get_secret_value () if self .config .api_key else None ,
4030 provider_data_api_key_field = "sambanova_api_key" ,
4131 openai_compat_api_base = self .config .url ,
32+ download_images = True , # SambaNova requires base64 image encoding
33+ json_schema_strict = False , # SambaNova doesn't support strict=True yet
4234 )
4335
44- async def _get_params (self , request : ChatCompletionRequest ) -> dict :
45- input_dict = {}
46-
47- input_dict ["messages" ] = [
48- await convert_message_to_openai_dict_new (m , download_images = True ) for m in request .messages
49- ]
50- if fmt := request .response_format :
51- if not isinstance (fmt , JsonSchemaResponseFormat ):
52- raise ValueError (
53- f"Unsupported response format: { type (fmt )} . Only JsonSchemaResponseFormat is supported."
54- )
55-
56- fmt = fmt .json_schema
57- name = fmt ["title" ]
58- del fmt ["title" ]
59- fmt ["additionalProperties" ] = False
60-
61- # Apply additionalProperties: False recursively to all objects
62- fmt = self ._add_additional_properties_recursive (fmt )
63-
64- input_dict ["response_format" ] = {
65- "type" : "json_schema" ,
66- "json_schema" : {
67- "name" : name ,
68- "schema" : fmt ,
69- "strict" : False ,
70- },
71- }
72- if request .tools :
73- input_dict ["tools" ] = [convert_tooldef_to_openai_tool (tool ) for tool in request .tools ]
74- if request .tool_config .tool_choice :
75- input_dict ["tool_choice" ] = (
76- request .tool_config .tool_choice .value
77- if isinstance (request .tool_config .tool_choice , ToolChoice )
78- else request .tool_config .tool_choice
79- )
80-
81- return {
82- "model" : request .model ,
83- "api_key" : self .get_api_key (),
84- "api_base" : self .api_base ,
85- ** input_dict ,
86- "stream" : request .stream ,
87- ** get_sampling_options (request .sampling_params ),
88- }
89-
9036 async def register_model (self , model : Model ) -> Model :
9137 model_id = self .get_provider_model_id (model .provider_resource_id )
9238
0 commit comments