44import platform
55from typing import Any , Dict , Iterator , Optional , TypedDict , List
66
7- from gptcli .completion import CompletionProvider , ModelOverrides , Message
7+ from gptcli .completion import Completion , CompletionProvider , ModelOverrides , Message
88from gptcli .google import GoogleCompletionProvider
99from gptcli .llama import LLaMACompletionProvider
1010from gptcli .openai import OpenAICompletionProvider
@@ -16,12 +16,14 @@ class AssistantConfig(TypedDict, total=False):
1616 model : str
1717 temperature : float
1818 top_p : float
19+ enable_code_execution : bool
1920
2021
2122CONFIG_DEFAULTS = {
2223 "model" : "gpt-3.5-turbo" ,
2324 "temperature" : 0.7 ,
2425 "top_p" : 1.0 ,
26+ "enable_code_execution" : False ,
2527}
2628
2729DEFAULT_ASSISTANTS : Dict [str , AssistantConfig ] = {
@@ -89,7 +91,7 @@ def init_messages(self) -> List[Message]:
8991 return self .config .get ("messages" , [])[:]
9092
9193 def supported_overrides (self ) -> List [str ]:
92- return ["model" , "temperature" , "top_p" ]
94+ return ["model" , "temperature" , "top_p" , "enable_code_execution" ]
9395
9496 def _param (self , param : str , override_params : ModelOverrides ) -> Any :
9597 # If the param is in the override_params, use that value
@@ -101,9 +103,15 @@ def _param(self, param: str, override_params: ModelOverrides) -> Any:
101103
102104 def complete_chat (
103105 self , messages , override_params : ModelOverrides = {}, stream : bool = True
104- ) -> Iterator [str ]:
106+ ) -> Iterator [Completion ]:
105107 model = self ._param ("model" , override_params )
106108 completion_provider = get_completion_provider (model )
109+
110+ enable_code_execution = (
111+ bool (self ._param ("enable_code_execution" , override_params ))
112+ and os .environ .get ("GPTCLI_ALLOW_CODE_EXECUTION" ) == "1"
113+ )
114+
107115 return completion_provider .complete (
108116 messages ,
109117 {
@@ -112,6 +120,7 @@ def complete_chat(
112120 "top_p" : float (self ._param ("top_p" , override_params )),
113121 },
114122 stream ,
123+ enable_code_execution ,
115124 )
116125
117126
0 commit comments