This repository was archived by the owner on Jun 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
src/codegate/providers/openrouter Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,32 @@ def normalize(self, data: Dict) -> ChatCompletionRequest:
22
22
return super ().normalize (data )
23
23
24
24
def denormalize (self , data : ChatCompletionRequest ) -> Dict :
25
- return super ().denormalize (data )
25
+ """
26
+ Denormalize a FIM OpenRouter request. Force it to be an accepted atext_completion format.
27
+ """
28
+ denormalized_data = super ().denormalize (data )
29
+ # We are forcing atext_completion which expects to have a "prompt" key in the data
30
+ # Forcing it in case is not present
31
+ if "prompt" in data :
32
+ return denormalized_data
33
+ custom_prompt = ""
34
+ for msg_dict in denormalized_data .get ("messages" , []):
35
+ content_obj = msg_dict .get ("content" )
36
+ if not content_obj :
37
+ continue
38
+ if isinstance (content_obj , list ):
39
+ for content_dict in content_obj :
40
+ custom_prompt += (
41
+ content_dict .get ("text" , "" ) if isinstance (content_dict , dict ) else ""
42
+ )
43
+ elif isinstance (content_obj , str ):
44
+ custom_prompt += content_obj
45
+
46
+ # Erase the original "messages" key. Replace it by "prompt"
47
+ del denormalized_data ["messages" ]
48
+ denormalized_data ["prompt" ] = custom_prompt
49
+
50
+ return denormalized_data
26
51
27
52
28
53
class OpenRouterProvider (OpenAIProvider ):
You can’t perform that action at this time.
0 commit comments