8
8
from langchain_openai import AzureChatOpenAI
9
9
from openai import APIConnectionError , APIStatusError , APITimeoutError
10
10
11
+ from template_langgraph .llms .foundry_locals import FoundryLocalWrapper
12
+ from template_langgraph .llms .foundry_locals import Settings as FoundryLocalSettings
11
13
from template_langgraph .loggers import get_logger
12
14
13
15
load_dotenv (override = True )
@@ -24,7 +26,7 @@ def image_to_base64(image_bytes: bytes) -> str:
24
26
"# Common Settings"
25
27
stream_mode = st .checkbox (
26
28
label = "ストリーム出力を有効にする" ,
27
- value = True ,
29
+ value = False ,
28
30
key = "STREAM_MODE" ,
29
31
)
30
32
"# Model"
@@ -33,6 +35,7 @@ def image_to_base64(image_bytes: bytes) -> str:
33
35
options = [
34
36
"azure" ,
35
37
"ollama" ,
38
+ "foundry_local" ,
36
39
],
37
40
index = 0 ,
38
41
key = "model_choice" ,
@@ -66,7 +69,6 @@ def image_to_base64(image_bytes: bytes) -> str:
66
69
"### Documents"
67
70
"[Azure Portal](https://portal.azure.com/)"
68
71
"[Azure OpenAI Studio](https://oai.azure.com/resource/overview)"
69
- "[View the source code](https://github.com/ks6088ts-labs/template-streamlit)"
70
72
elif model_choice == "ollama" :
71
73
ollama_model_chat = st .text_input (
72
74
label = "OLLAMA_MODEL_CHAT" ,
@@ -76,10 +78,18 @@ def image_to_base64(image_bytes: bytes) -> str:
76
78
)
77
79
"### Documents"
78
80
"[Ollama Docs](https://github.com/ollama/ollama)"
79
- "[View the source code](https://github.com/ks6088ts-labs/template-streamlit)"
81
+ elif model_choice == "foundry_local" :
82
+ foundry_local_model_chat = st .text_input (
83
+ label = "FOUNDRY_LOCAL_MODEL_CHAT" ,
84
+ value = getenv ("FOUNDRY_LOCAL_MODEL_CHAT" , "phi-3-mini-4k" ),
85
+ key = "FOUNDRY_LOCAL_MODEL_CHAT" ,
86
+ type = "default" ,
87
+ )
88
+ "### Documents"
89
+ "[Get started with Foundry Local](https://learn.microsoft.com/en-us/azure/ai-foundry/foundry-local/get-started)"
80
90
else :
81
- st .error ("Invalid model choice. Please select either 'azure' or 'ollama '." )
82
- raise ValueError ("Invalid model choice. Please select either 'azure' or 'ollama '." )
91
+ st .error ("Invalid model choice. Please select either 'azure', 'ollama', or 'foundry_local '." )
92
+ raise ValueError ("Invalid model choice. Please select either 'azure', 'ollama', or 'foundry_local '." )
83
93
84
94
85
95
def is_azure_configured ():
@@ -96,8 +106,12 @@ def is_ollama_configured():
96
106
return st .session_state .get ("OLLAMA_MODEL_CHAT" ) and st .session_state .get ("model_choice" ) == "ollama"
97
107
98
108
109
+ def is_foundry_local_configured ():
110
+ return st .session_state .get ("FOUNDRY_LOCAL_MODEL_CHAT" ) and st .session_state .get ("model_choice" ) == "foundry_local"
111
+
112
+
99
113
def is_configured ():
100
- return is_azure_configured () or is_ollama_configured ()
114
+ return is_azure_configured () or is_ollama_configured () or is_foundry_local_configured ()
101
115
102
116
103
117
def get_model ():
@@ -112,7 +126,13 @@ def get_model():
112
126
return ChatOllama (
113
127
model = st .session_state .get ("OLLAMA_MODEL_CHAT" , "" ),
114
128
)
115
- raise ValueError ("No model is configured. Please set up the Azure or Ollama model in the sidebar." )
129
+ elif is_foundry_local_configured ():
130
+ return FoundryLocalWrapper (
131
+ settings = FoundryLocalSettings (
132
+ foundry_local_model_chat = st .session_state .get ("FOUNDRY_LOCAL_MODEL_CHAT" , "phi-3-mini-4k" ),
133
+ )
134
+ ).chat_model
135
+ raise ValueError ("No model is configured. Please set up the Azure, Ollama, or Foundry Local model in the sidebar." )
116
136
117
137
118
138
st .title ("Chat Playground" )
0 commit comments