Spaces:
Runtime error
Runtime error
Update chain_app.py
Browse files- chain_app.py +622 -610
chain_app.py
CHANGED
|
@@ -1907,634 +1907,646 @@ async def on_chat_start():
|
|
| 1907 |
@cl.on_message
|
| 1908 |
async def main(message: cl.Message):
|
| 1909 |
chat_profile = cl.user_session.get("chat_profile")
|
| 1910 |
-
|
| 1911 |
-
|
| 1912 |
-
|
| 1913 |
-
|
| 1914 |
-
|
| 1915 |
-
|
| 1916 |
-
|
| 1917 |
-
|
| 1918 |
-
|
| 1919 |
await cl.Message(
|
| 1920 |
-
content=
|
| 1921 |
).send()
|
| 1922 |
-
|
| 1923 |
-
|
| 1924 |
-
|
| 1925 |
-
|
| 1926 |
-
|
| 1927 |
-
|
| 1928 |
-
|
| 1929 |
-
|
| 1930 |
-
|
| 1931 |
-
|
| 1932 |
-
|
| 1933 |
-
|
| 1934 |
-
|
| 1935 |
-
|
| 1936 |
-
|
| 1937 |
-
|
| 1938 |
-
|
| 1939 |
-
|
| 1940 |
-
|
| 1941 |
-
|
| 1942 |
-
|
| 1943 |
-
|
| 1944 |
-
|
| 1945 |
-
|
| 1946 |
-
|
| 1947 |
-
|
| 1948 |
-
|
| 1949 |
-
|
| 1950 |
-
|
| 1951 |
-
|
| 1952 |
-
|
| 1953 |
-
|
| 1954 |
-
|
| 1955 |
-
|
| 1956 |
-
|
| 1957 |
-
|
| 1958 |
-
|
| 1959 |
-
|
| 1960 |
-
|
| 1961 |
-
|
| 1962 |
-
|
| 1963 |
-
|
| 1964 |
-
|
| 1965 |
-
|
| 1966 |
-
|
| 1967 |
-
|
| 1968 |
-
|
| 1969 |
-
|
| 1970 |
-
|
| 1971 |
-
|
| 1972 |
-
|
| 1973 |
-
|
| 1974 |
-
|
| 1975 |
-
|
| 1976 |
-
|
| 1977 |
-
|
| 1978 |
-
|
| 1979 |
-
|
| 1980 |
-
|
| 1981 |
-
|
| 1982 |
-
|
| 1983 |
-
|
| 1984 |
-
|
| 1985 |
-
|
| 1986 |
-
|
| 1987 |
-
|
| 1988 |
-
|
| 1989 |
-
|
| 1990 |
-
|
| 1991 |
-
|
| 1992 |
-
|
| 1993 |
-
|
| 1994 |
-
|
| 1995 |
-
|
| 1996 |
-
|
| 1997 |
-
|
| 1998 |
-
|
| 1999 |
-
|
| 2000 |
-
|
| 2001 |
-
|
| 2002 |
-
|
| 2003 |
-
|
| 2004 |
-
|
| 2005 |
-
|
| 2006 |
-
|
| 2007 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2008 |
]
|
| 2009 |
-
|
| 2010 |
-
|
| 2011 |
-
|
| 2012 |
-
|
| 2013 |
-
|
| 2014 |
-
|
| 2015 |
-
|
| 2016 |
-
|
| 2017 |
-
|
| 2018 |
-
|
| 2019 |
-
|
| 2020 |
-
|
| 2021 |
-
|
| 2022 |
-
|
| 2023 |
-
|
| 2024 |
-
|
| 2025 |
-
|
| 2026 |
-
|
| 2027 |
-
|
| 2028 |
-
|
| 2029 |
-
|
| 2030 |
-
|
| 2031 |
-
|
| 2032 |
-
|
| 2033 |
-
|
| 2034 |
-
|
| 2035 |
-
|
| 2036 |
-
|
| 2037 |
-
|
| 2038 |
-
|
| 2039 |
-
|
| 2040 |
-
|
| 2041 |
-
|
| 2042 |
-
|
| 2043 |
-
|
| 2044 |
-
|
| 2045 |
-
|
| 2046 |
-
|
| 2047 |
-
|
| 2048 |
-
|
| 2049 |
-
|
| 2050 |
-
|
| 2051 |
-
|
| 2052 |
-
|
| 2053 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2054 |
|
| 2055 |
-
|
| 2056 |
-
|
| 2057 |
-
|
| 2058 |
-
|
| 2059 |
-
|
| 2060 |
-
|
| 2061 |
-
|
| 2062 |
-
|
| 2063 |
-
|
| 2064 |
-
|
| 2065 |
-
).send()
|
| 2066 |
-
|
| 2067 |
-
elif chat_profile == 'Qwen2-1.5B':
|
| 2068 |
-
client = Client("Qwen/Qwen2-1.5b-instruct-demo", hf_token=hf_token)
|
| 2069 |
-
result = client.predict(
|
| 2070 |
-
query=message.content,
|
| 2071 |
-
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2072 |
-
api_name="/model_chat"
|
| 2073 |
-
)
|
| 2074 |
-
await cl.Message(
|
| 2075 |
-
content=result[1][0][1]
|
| 2076 |
-
|
| 2077 |
-
).send()
|
| 2078 |
-
|
| 2079 |
-
elif chat_profile == 'Qwen2-0.5B':
|
| 2080 |
-
client = Client("Qwen/Qwen2-0.5B-Instruct", hf_token=hf_token)
|
| 2081 |
-
result = client.predict(
|
| 2082 |
-
query=message.content,
|
| 2083 |
-
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2084 |
-
api_name="/model_chat"
|
| 2085 |
-
)
|
| 2086 |
-
await cl.Message(
|
| 2087 |
-
content=result[1][0][1]
|
| 2088 |
-
|
| 2089 |
-
).send()
|
| 2090 |
-
elif chat_profile == 'Qwen1.5-110B':
|
| 2091 |
-
client = Client("Qwen/Qwen1.5-110B-Chat-demo", hf_token=hf_token)
|
| 2092 |
-
result = client.predict(
|
| 2093 |
-
query=message.content,
|
| 2094 |
-
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2095 |
-
api_name="/model_chat"
|
| 2096 |
-
)
|
| 2097 |
-
await cl.Message(
|
| 2098 |
-
content=result[1][0][1]
|
| 2099 |
-
|
| 2100 |
-
).send()
|
| 2101 |
-
|
| 2102 |
-
elif chat_profile == 'Qwen1.5-32B':
|
| 2103 |
-
client = Client("Qwen/Qwen1.5-32B-Chat-demo", hf_token=hf_token)
|
| 2104 |
-
result = client.predict(
|
| 2105 |
-
query=message.content,
|
| 2106 |
-
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2107 |
-
api_name="/model_chat"
|
| 2108 |
-
)
|
| 2109 |
-
await cl.Message(
|
| 2110 |
-
content=result[1][0][1]
|
| 2111 |
-
|
| 2112 |
-
).send()
|
| 2113 |
-
|
| 2114 |
-
elif chat_profile == 'Qwen1.5-2.7B':
|
| 2115 |
-
client = Client("Qwen/qwen1.5-MoE-A2.7B-Chat-demo", hf_token=hf_token)
|
| 2116 |
-
result = client.predict(
|
| 2117 |
-
query=message.content,
|
| 2118 |
-
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2119 |
-
api_name="/model_chat"
|
| 2120 |
-
)
|
| 2121 |
-
await cl.Message(
|
| 2122 |
-
content=result[1][0][1]
|
| 2123 |
-
|
| 2124 |
-
).send()
|
| 2125 |
-
|
| 2126 |
-
# elif chat_profile == 'Qwen-14B':
|
| 2127 |
-
# client = Client("Qwen/qwen1.5-MoE-A2.7B-Chat-demo", hf_token=hf_token)
|
| 2128 |
-
# result = client.predict(
|
| 2129 |
-
# query=message.content,
|
| 2130 |
-
# system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2131 |
-
# api_name="/model_chat"
|
| 2132 |
-
# )
|
| 2133 |
-
# await cl.Message(
|
| 2134 |
-
# content=result[1][0][1]
|
| 2135 |
-
|
| 2136 |
-
# ).send()
|
| 2137 |
-
|
| 2138 |
-
# elif chat_profile == 'Qwen-7B':
|
| 2139 |
-
# client = Client("Qwen/qwen1.5-MoE-A2.7B-Chat-demo", hf_token=hf_token)
|
| 2140 |
-
# result = client.predict(
|
| 2141 |
-
# query=message.content,
|
| 2142 |
-
# system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2143 |
-
# api_name="/model_chat"
|
| 2144 |
-
# )
|
| 2145 |
-
# await cl.Message(
|
| 2146 |
-
# content=result[1][0][1]
|
| 2147 |
-
|
| 2148 |
-
# ).send()
|
| 2149 |
|
| 2150 |
-
|
| 2151 |
-
|
| 2152 |
-
model="llama-3.1-405b-reasoning",
|
| 2153 |
-
messages=[
|
| 2154 |
-
{
|
| 2155 |
-
"role": "user",
|
| 2156 |
-
"content": message.content
|
| 2157 |
-
}
|
| 2158 |
-
],
|
| 2159 |
-
temperature=1,
|
| 2160 |
-
max_tokens=1024,
|
| 2161 |
-
top_p=1,
|
| 2162 |
-
stream=True,
|
| 2163 |
-
stop=None,
|
| 2164 |
-
)
|
| 2165 |
|
| 2166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2167 |
|
| 2168 |
-
|
| 2169 |
-
|
| 2170 |
-
|
| 2171 |
-
|
| 2172 |
-
|
| 2173 |
-
|
| 2174 |
-
|
| 2175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2176 |
|
| 2177 |
-
|
| 2178 |
-
|
| 2179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2180 |
|
| 2181 |
-
|
| 2182 |
-
completion = groq_client.chat.completions.create(
|
| 2183 |
-
model="llama-3.1-70b-versatile",
|
| 2184 |
-
messages=[
|
| 2185 |
-
{
|
| 2186 |
-
"role": "user",
|
| 2187 |
-
"content": message.content
|
| 2188 |
-
}
|
| 2189 |
-
],
|
| 2190 |
-
temperature=1,
|
| 2191 |
-
max_tokens=1024,
|
| 2192 |
-
top_p=1,
|
| 2193 |
-
stream=True,
|
| 2194 |
-
stop=None,
|
| 2195 |
-
)
|
| 2196 |
|
| 2197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2198 |
|
| 2199 |
-
|
| 2200 |
-
|
| 2201 |
-
# Retrieve the content from the current chunk
|
| 2202 |
-
content = chunk.choices[0].delta.content
|
| 2203 |
-
|
| 2204 |
-
# Check if the content is not None before concatenating it
|
| 2205 |
-
if content is not None:
|
| 2206 |
-
complete_content += content
|
| 2207 |
|
| 2208 |
-
|
| 2209 |
-
|
| 2210 |
-
|
| 2211 |
-
|
| 2212 |
-
|
| 2213 |
-
|
| 2214 |
-
|
| 2215 |
-
|
| 2216 |
-
|
| 2217 |
-
|
| 2218 |
-
|
| 2219 |
-
|
| 2220 |
-
|
| 2221 |
-
|
| 2222 |
-
|
| 2223 |
-
stream=True,
|
| 2224 |
-
stop=None,
|
| 2225 |
-
)
|
| 2226 |
|
| 2227 |
-
|
| 2228 |
|
| 2229 |
-
|
| 2230 |
-
|
| 2231 |
-
|
| 2232 |
-
|
| 2233 |
-
|
| 2234 |
-
|
| 2235 |
-
|
| 2236 |
-
|
| 2237 |
|
| 2238 |
-
|
| 2239 |
-
|
| 2240 |
-
|
| 2241 |
-
|
| 2242 |
-
|
| 2243 |
-
|
| 2244 |
-
|
| 2245 |
-
|
| 2246 |
-
|
| 2247 |
-
|
| 2248 |
-
|
| 2249 |
-
|
| 2250 |
-
|
| 2251 |
-
|
| 2252 |
-
|
| 2253 |
-
|
| 2254 |
-
|
| 2255 |
-
|
| 2256 |
-
|
| 2257 |
-
|
| 2258 |
-
|
| 2259 |
-
|
| 2260 |
-
|
| 2261 |
-
|
| 2262 |
-
|
| 2263 |
-
|
| 2264 |
-
|
| 2265 |
-
|
| 2266 |
-
|
| 2267 |
-
|
| 2268 |
-
|
| 2269 |
-
|
| 2270 |
-
|
| 2271 |
-
elif chat_profile == 'Llama-3-8B':
|
| 2272 |
-
completion = groq_client.chat.completions.create(
|
| 2273 |
-
model="llama3-8b-8192",
|
| 2274 |
-
messages=[
|
| 2275 |
-
{
|
| 2276 |
-
"role": "user",
|
| 2277 |
-
"content": message.content
|
| 2278 |
-
}
|
| 2279 |
-
],
|
| 2280 |
-
temperature=1,
|
| 2281 |
-
max_tokens=1024,
|
| 2282 |
-
top_p=1,
|
| 2283 |
-
stream=True,
|
| 2284 |
-
stop=None,
|
| 2285 |
-
)
|
| 2286 |
-
|
| 2287 |
-
complete_content = ""
|
| 2288 |
-
|
| 2289 |
-
# Iterate over each chunk
|
| 2290 |
-
for chunk in completion:
|
| 2291 |
-
# Retrieve the content from the current chunk
|
| 2292 |
-
content = chunk.choices[0].delta.content
|
| 2293 |
-
|
| 2294 |
-
# Check if the content is not None before concatenating it
|
| 2295 |
-
if content is not None:
|
| 2296 |
-
complete_content += content
|
| 2297 |
-
|
| 2298 |
-
# Send the concatenated content as a message
|
| 2299 |
-
await cl.Message(content=complete_content).send()
|
| 2300 |
-
|
| 2301 |
-
elif chat_profile == 'gemma2-9B':
|
| 2302 |
-
completion = groq_client.chat.completions.create(
|
| 2303 |
-
model="gemma2-9b-it",
|
| 2304 |
-
messages=[
|
| 2305 |
-
{
|
| 2306 |
-
"role": "user",
|
| 2307 |
-
"content": message.content
|
| 2308 |
-
}
|
| 2309 |
-
],
|
| 2310 |
-
temperature=1,
|
| 2311 |
-
max_tokens=1024,
|
| 2312 |
-
top_p=1,
|
| 2313 |
-
stream=True,
|
| 2314 |
-
stop=None,
|
| 2315 |
-
)
|
| 2316 |
-
|
| 2317 |
-
complete_content = ""
|
| 2318 |
-
|
| 2319 |
-
# Iterate over each chunk
|
| 2320 |
-
for chunk in completion:
|
| 2321 |
-
# Retrieve the content from the current chunk
|
| 2322 |
-
content = chunk.choices[0].delta.content
|
| 2323 |
-
|
| 2324 |
-
# Check if the content is not None before concatenating it
|
| 2325 |
-
if content is not None:
|
| 2326 |
-
complete_content += content
|
| 2327 |
-
|
| 2328 |
-
# Send the concatenated content as a message
|
| 2329 |
-
await cl.Message(content=complete_content).send()
|
| 2330 |
-
|
| 2331 |
-
elif chat_profile == 'gemma-7B':
|
| 2332 |
-
completion = groq_client.chat.completions.create(
|
| 2333 |
-
model="gemma-7b-it",
|
| 2334 |
-
messages=[
|
| 2335 |
-
{
|
| 2336 |
-
"role": "user",
|
| 2337 |
-
"content": message.content
|
| 2338 |
-
}
|
| 2339 |
-
],
|
| 2340 |
-
temperature=1,
|
| 2341 |
-
max_tokens=1024,
|
| 2342 |
-
top_p=1,
|
| 2343 |
-
stream=True,
|
| 2344 |
-
stop=None,
|
| 2345 |
-
)
|
| 2346 |
-
|
| 2347 |
-
complete_content = ""
|
| 2348 |
-
|
| 2349 |
-
# Iterate over each chunk
|
| 2350 |
-
for chunk in completion:
|
| 2351 |
-
# Retrieve the content from the current chunk
|
| 2352 |
-
content = chunk.choices[0].delta.content
|
| 2353 |
-
|
| 2354 |
-
# Check if the content is not None before concatenating it
|
| 2355 |
-
if content is not None:
|
| 2356 |
-
complete_content += content
|
| 2357 |
-
|
| 2358 |
-
# Send the concatenated content as a message
|
| 2359 |
-
await cl.Message(content=complete_content).send()
|
| 2360 |
|
| 2361 |
-
|
| 2362 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2363 |
message=message.content,
|
| 2364 |
-
|
| 2365 |
-
|
| 2366 |
-
|
| 2367 |
-
|
| 2368 |
-
|
| 2369 |
-
|
| 2370 |
-
|
| 2371 |
-
|
| 2372 |
-
|
| 2373 |
-
|
| 2374 |
-
|
| 2375 |
-
|
| 2376 |
-
|
| 2377 |
-
|
| 2378 |
-
|
| 2379 |
-
|
| 2380 |
-
|
| 2381 |
-
|
| 2382 |
-
|
| 2383 |
-
],
|
| 2384 |
-
|
| 2385 |
-
|
| 2386 |
-
|
| 2387 |
-
stream
|
| 2388 |
-
|
| 2389 |
-
|
| 2390 |
-
|
| 2391 |
-
|
| 2392 |
-
|
| 2393 |
-
|
| 2394 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2395 |
|
| 2396 |
-
|
| 2397 |
-
|
| 2398 |
-
|
| 2399 |
-
|
| 2400 |
-
|
| 2401 |
-
|
| 2402 |
-
|
| 2403 |
-
|
| 2404 |
-
|
| 2405 |
-
|
| 2406 |
-
|
| 2407 |
-
|
| 2408 |
-
|
| 2409 |
-
|
| 2410 |
-
|
| 2411 |
-
|
| 2412 |
-
|
| 2413 |
-
|
| 2414 |
-
|
| 2415 |
-
|
| 2416 |
-
|
| 2417 |
-
|
| 2418 |
-
|
| 2419 |
-
|
| 2420 |
-
|
| 2421 |
-
|
| 2422 |
-
|
| 2423 |
-
|
| 2424 |
-
|
| 2425 |
-
|
| 2426 |
-
|
| 2427 |
-
|
| 2428 |
-
|
| 2429 |
-
|
| 2430 |
-
|
| 2431 |
-
|
| 2432 |
-
|
| 2433 |
-
|
| 2434 |
-
|
| 2435 |
-
|
| 2436 |
-
|
| 2437 |
-
await cl.Message(content=complete_content).send()
|
| 2438 |
-
|
| 2439 |
-
elif chat_profile == 'Aya-35B':
|
| 2440 |
-
stream = co.chat_stream(
|
| 2441 |
-
model='c4ai-aya-23',
|
| 2442 |
-
message=message.content,
|
| 2443 |
-
temperature=0.3,
|
| 2444 |
-
# chat_history=[{"role": "User", "message": "Hello"}, {"role": "Chatbot", "message": "Hello! How can I help you today?"}, {"role": "User", "message": "Hi"}, {"role": "User", "message": "hello"}],
|
| 2445 |
-
prompt_truncation='OFF',
|
| 2446 |
-
connectors=[],
|
| 2447 |
-
)
|
| 2448 |
-
|
| 2449 |
-
complete_content = ''
|
| 2450 |
-
for event in stream:
|
| 2451 |
-
if event.event_type == 'text-generation':
|
| 2452 |
-
complete_content += event.text
|
| 2453 |
-
await cl.Message(content=complete_content).send()
|
| 2454 |
-
|
| 2455 |
-
elif chat_profile == 'Command-R-Plus':
|
| 2456 |
-
stream = co.chat_stream(
|
| 2457 |
-
model='command-r-plus',
|
| 2458 |
-
message=message.content,
|
| 2459 |
-
temperature=0.3,
|
| 2460 |
-
chat_history=[],
|
| 2461 |
-
prompt_truncation='AUTO',
|
| 2462 |
-
)
|
| 2463 |
-
complete_content = ''
|
| 2464 |
-
for event in stream:
|
| 2465 |
-
if event.event_type == 'text-generation':
|
| 2466 |
-
complete_content += event.text
|
| 2467 |
-
await cl.Message(content=complete_content).send()
|
| 2468 |
-
|
| 2469 |
-
elif chat_profile == 'Command-R':
|
| 2470 |
-
stream = co.chat_stream(
|
| 2471 |
-
model='command-r',
|
| 2472 |
-
message=message.content,
|
| 2473 |
-
temperature=0.3,
|
| 2474 |
-
chat_history=[],
|
| 2475 |
-
prompt_truncation='AUTO',
|
| 2476 |
-
)
|
| 2477 |
-
complete_content = ''
|
| 2478 |
-
for event in stream:
|
| 2479 |
-
if event.event_type == 'text-generation':
|
| 2480 |
-
complete_content += event.text
|
| 2481 |
-
await cl.Message(content=complete_content).send()
|
| 2482 |
-
|
| 2483 |
-
elif chat_profile == 'Command':
|
| 2484 |
-
stream = co.chat_stream(
|
| 2485 |
-
model='command',
|
| 2486 |
-
message=message.content,
|
| 2487 |
-
temperature=0.3,
|
| 2488 |
-
chat_history=[],
|
| 2489 |
-
prompt_truncation='AUTO',
|
| 2490 |
-
)
|
| 2491 |
-
complete_content = ''
|
| 2492 |
-
for event in stream:
|
| 2493 |
-
if event.event_type == 'text-generation':
|
| 2494 |
-
complete_content += event.text
|
| 2495 |
-
await cl.Message(content=complete_content).send()
|
| 2496 |
-
|
| 2497 |
-
elif chat_profile == 'Command-Light':
|
| 2498 |
-
stream = co.chat_stream(
|
| 2499 |
-
model='command-light',
|
| 2500 |
-
message=message.content,
|
| 2501 |
-
temperature=0.3,
|
| 2502 |
-
chat_history=[],
|
| 2503 |
-
prompt_truncation='AUTO',
|
| 2504 |
-
)
|
| 2505 |
-
complete_content = ''
|
| 2506 |
-
for event in stream:
|
| 2507 |
-
if event.event_type == 'text-generation':
|
| 2508 |
-
complete_content += event.text
|
| 2509 |
-
await cl.Message(content=complete_content).send()
|
| 2510 |
-
|
| 2511 |
-
elif chat_profile == 'Command-Light-Nightly':
|
| 2512 |
-
stream = co.chat_stream(
|
| 2513 |
-
model='command-light-nightly',
|
| 2514 |
-
message=message.content,
|
| 2515 |
-
temperature=0.3,
|
| 2516 |
-
chat_history=[],
|
| 2517 |
-
prompt_truncation='AUTO',
|
| 2518 |
-
)
|
| 2519 |
-
complete_content = ''
|
| 2520 |
-
for event in stream:
|
| 2521 |
-
if event.event_type == 'text-generation':
|
| 2522 |
-
complete_content += event.text
|
| 2523 |
-
await cl.Message(content=complete_content).send()
|
| 2524 |
-
|
| 2525 |
-
elif chat_profile == 'Command-Nightly':
|
| 2526 |
-
stream = co.chat_stream(
|
| 2527 |
-
model='command-light-nightly',
|
| 2528 |
-
message=message.content,
|
| 2529 |
-
temperature=0.3,
|
| 2530 |
-
chat_history=[],
|
| 2531 |
-
prompt_truncation='AUTO',
|
| 2532 |
-
)
|
| 2533 |
-
complete_content = ''
|
| 2534 |
-
for event in stream:
|
| 2535 |
-
if event.event_type == 'text-generation':
|
| 2536 |
-
complete_content += event.text
|
| 2537 |
-
await cl.Message(content=complete_content).send()
|
| 2538 |
|
| 2539 |
@cl.on_settings_update
|
| 2540 |
async def setup_agent(settings):
|
|
|
|
| 1907 |
@cl.on_message
|
| 1908 |
async def main(message: cl.Message):
|
| 1909 |
chat_profile = cl.user_session.get("chat_profile")
|
| 1910 |
+
res = await cl.AskActionMessage(
|
| 1911 |
+
content="Pick an action!",
|
| 1912 |
+
actions=[
|
| 1913 |
+
cl.Action(name="continue", value="continue", label="✅ Continue"),
|
| 1914 |
+
cl.Action(name="cancel", value="cancel", label="❌ Cancel"),
|
| 1915 |
+
],
|
| 1916 |
+
).send()
|
| 1917 |
+
|
| 1918 |
+
if res and res.get("value") == "continue":
|
| 1919 |
await cl.Message(
|
| 1920 |
+
content="Continue!",
|
| 1921 |
).send()
|
| 1922 |
+
if chat_profile == 'neural-brain-AI':
|
| 1923 |
+
completion = openai_client.chat.completions.create(
|
| 1924 |
+
model="ft:gpt-3.5-turbo-1106:nb:aria1:9UWDrLJK",
|
| 1925 |
+
messages=[
|
| 1926 |
+
{"role": "system", "content": "You are neural nexus official chatbot, you are made by Artin Daneshvar and Sadra Noadoust"},
|
| 1927 |
+
{"role": "user", "content": message.content}
|
| 1928 |
+
]
|
| 1929 |
+
)
|
| 1930 |
+
model_response = completion.choices[0].message.content
|
| 1931 |
+
await cl.Message(
|
| 1932 |
+
content=model_response
|
| 1933 |
+
).send()
|
| 1934 |
+
|
| 1935 |
+
elif chat_profile == "Dorna-AI":
|
| 1936 |
+
result = hf_text_client.predict(
|
| 1937 |
+
message=message.content,
|
| 1938 |
+
request="your name is Dorna,An AI Assistant designed by neural nexus team. i was made by Artin Daneshvar and Sadra Noadoust, 2 iranian students!",
|
| 1939 |
+
param_3=512,
|
| 1940 |
+
param_4=0.7,
|
| 1941 |
+
param_5=0.95,
|
| 1942 |
+
api_name="/chat"
|
| 1943 |
+
)
|
| 1944 |
+
model_response = result.strip("</s>")
|
| 1945 |
+
await cl.Message(
|
| 1946 |
+
content=model_response
|
| 1947 |
+
).send()
|
| 1948 |
+
elif chat_profile == "gpt4-o-mini":
|
| 1949 |
+
completion = openai_client.chat.completions.create(
|
| 1950 |
+
model="gpt-4o-mini",
|
| 1951 |
+
messages=[
|
| 1952 |
+
{"role": "system", "content": "You are neural nexus official chatbot, you are made by Artin Daneshvar and Sadra Noadoust"},
|
| 1953 |
+
{"role": "user", "content": message.content}
|
| 1954 |
+
]
|
| 1955 |
+
)
|
| 1956 |
+
model_response = completion.choices[0].message.content
|
| 1957 |
+
await cl.Message(
|
| 1958 |
+
content=model_response
|
| 1959 |
+
).send()
|
| 1960 |
+
# elif chat_profile == 'Image-Generation':
|
| 1961 |
+
# result = hf_image_client.predict(
|
| 1962 |
+
# prompt=message.content,
|
| 1963 |
+
# negative_prompt="",
|
| 1964 |
+
# seed=0,
|
| 1965 |
+
# randomize_seed=True,
|
| 1966 |
+
# width=512,
|
| 1967 |
+
# height=512,
|
| 1968 |
+
# guidance_scale=0,
|
| 1969 |
+
# num_inference_steps=2,
|
| 1970 |
+
# api_name="/infer"
|
| 1971 |
+
# )
|
| 1972 |
+
# image = cl.Image(path=result, name="result", display="inline")
|
| 1973 |
+
# await cl.Message(
|
| 1974 |
+
# content="This message has an image!",
|
| 1975 |
+
# elements=[image],
|
| 1976 |
+
# ).send()
|
| 1977 |
+
elif chat_profile == 'GPT-4':
|
| 1978 |
+
completion = openai_client.chat.completions.create(
|
| 1979 |
+
model="gpt-4",
|
| 1980 |
+
messages=[
|
| 1981 |
+
{"role": "system", "content": "You are neural nexus official chatbot, you are made by Artin Daneshvar and Sadra Noadoust"},
|
| 1982 |
+
{"role": "user", "content": message.content}
|
| 1983 |
+
]
|
| 1984 |
+
)
|
| 1985 |
+
model_response = completion.choices[0].message.content
|
| 1986 |
+
await cl.Message(
|
| 1987 |
+
content=model_response
|
| 1988 |
+
).send()
|
| 1989 |
+
|
| 1990 |
+
elif chat_profile == 'gpt-3.5-turbo':
|
| 1991 |
+
completion = openai_client.chat.completions.create(
|
| 1992 |
+
model="gpt-3.5-turbo",
|
| 1993 |
+
messages=[
|
| 1994 |
+
{"role": "system", "content": "You are neural nexus official chatbot, you are made by Artin Daneshvar and Sadra Noadoust"},
|
| 1995 |
+
{"role": "user", "content": message.content}
|
| 1996 |
+
]
|
| 1997 |
+
)
|
| 1998 |
+
model_response = completion.choices[0].message.content
|
| 1999 |
+
await cl.Message(
|
| 2000 |
+
content=model_response
|
| 2001 |
+
).send()
|
| 2002 |
+
elif chat_profile == 'GPT-3.5-turbo-0125':
|
| 2003 |
+
completion = openai_client.chat.completions.create(
|
| 2004 |
+
model="GPT-3.5-turbo-0125",
|
| 2005 |
+
messages=[
|
| 2006 |
+
{"role": "system", "content": "You are neural nexus official chatbot, you are made by Artin Daneshvar and Sadra Noadoust"},
|
| 2007 |
+
{"role": "user", "content": message.content}
|
| 2008 |
+
]
|
| 2009 |
+
)
|
| 2010 |
+
model_response = completion.choices[0].message.content
|
| 2011 |
+
await cl.Message(
|
| 2012 |
+
content=model_response
|
| 2013 |
+
).send()
|
| 2014 |
+
elif chat_profile == 'gpt-3.5-turbo-1106':
|
| 2015 |
+
completion = openai_client.chat.completions.create(
|
| 2016 |
+
model="gpt-3.5-turbo-1106",
|
| 2017 |
+
messages=[
|
| 2018 |
+
{"role": "system", "content": "You are neural nexus official chatbot, you are made by Artin Daneshvar and Sadra Noadoust"},
|
| 2019 |
+
{"role": "user", "content": message.content}
|
| 2020 |
+
]
|
| 2021 |
+
)
|
| 2022 |
+
model_response = completion.choices[0].message.content
|
| 2023 |
+
await cl.Message(
|
| 2024 |
+
content=model_response
|
| 2025 |
+
).send()
|
| 2026 |
+
# elif chat_profile == 'davinci-002':
|
| 2027 |
+
# completion = openai_client.chat.completions.create(
|
| 2028 |
+
# model="davinci-002",
|
| 2029 |
+
# messages=[
|
| 2030 |
+
# {"role": "system", "content": "You are neural nexus official chatbot, you are made by Artin Daneshvar and Sadra Noadoust"},
|
| 2031 |
+
# {"role": "user", "content": message.content}
|
| 2032 |
+
# ]
|
| 2033 |
+
# )
|
| 2034 |
+
# model_response = completion.choices[0].message.content
|
| 2035 |
+
# await cl.Message(
|
| 2036 |
+
# content=model_response
|
| 2037 |
+
# ).send()
|
| 2038 |
+
|
| 2039 |
+
elif chat_profile == 'TTS':
|
| 2040 |
+
response = openai_client.audio.speech.create(
|
| 2041 |
+
model="tts-1",
|
| 2042 |
+
voice="alloy",
|
| 2043 |
+
input=message.content,
|
| 2044 |
+
)
|
| 2045 |
+
|
| 2046 |
+
response.stream_to_file("output.mp3")
|
| 2047 |
+
|
| 2048 |
+
elements = [
|
| 2049 |
+
cl.Audio(name="output.mp3", path="./output.mp3", display="inline"),
|
| 2050 |
]
|
| 2051 |
+
await cl.Message(
|
| 2052 |
+
content="Here it is the response!",
|
| 2053 |
+
elements=elements,
|
| 2054 |
+
).send()
|
| 2055 |
+
|
| 2056 |
+
elif chat_profile == 'Qwen2-57B':
|
| 2057 |
+
client = Client("Qwen/Qwen2-57b-a14b-instruct-demo", hf_token=hf_token)
|
| 2058 |
+
result = client.predict(
|
| 2059 |
+
query=message.content,
|
| 2060 |
+
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2061 |
+
api_name="/model_chat"
|
| 2062 |
+
)
|
| 2063 |
+
await cl.Message(
|
| 2064 |
+
content=result[1][0][1]
|
| 2065 |
+
).send()
|
| 2066 |
+
|
| 2067 |
+
elif chat_profile == 'Qwen2-7B':
|
| 2068 |
+
client = Client("Qwen/Qwen2-7b-instruct-demo", hf_token=hf_token)
|
| 2069 |
+
result = client.predict(
|
| 2070 |
+
query=message.content,
|
| 2071 |
+
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2072 |
+
api_name="/model_chat"
|
| 2073 |
+
)
|
| 2074 |
+
await cl.Message(
|
| 2075 |
+
content=result[1][0][1]
|
| 2076 |
+
|
| 2077 |
+
).send()
|
| 2078 |
+
|
| 2079 |
+
elif chat_profile == 'Qwen2-1.5B':
|
| 2080 |
+
client = Client("Qwen/Qwen2-1.5b-instruct-demo", hf_token=hf_token)
|
| 2081 |
+
result = client.predict(
|
| 2082 |
+
query=message.content,
|
| 2083 |
+
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2084 |
+
api_name="/model_chat"
|
| 2085 |
+
)
|
| 2086 |
+
await cl.Message(
|
| 2087 |
+
content=result[1][0][1]
|
| 2088 |
+
|
| 2089 |
+
).send()
|
| 2090 |
+
|
| 2091 |
+
elif chat_profile == 'Qwen2-0.5B':
|
| 2092 |
+
client = Client("Qwen/Qwen2-0.5B-Instruct", hf_token=hf_token)
|
| 2093 |
+
result = client.predict(
|
| 2094 |
+
query=message.content,
|
| 2095 |
+
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2096 |
+
api_name="/model_chat"
|
| 2097 |
+
)
|
| 2098 |
+
await cl.Message(
|
| 2099 |
+
content=result[1][0][1]
|
| 2100 |
+
|
| 2101 |
+
).send()
|
| 2102 |
+
elif chat_profile == 'Qwen1.5-110B':
|
| 2103 |
+
client = Client("Qwen/Qwen1.5-110B-Chat-demo", hf_token=hf_token)
|
| 2104 |
+
result = client.predict(
|
| 2105 |
+
query=message.content,
|
| 2106 |
+
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2107 |
+
api_name="/model_chat"
|
| 2108 |
+
)
|
| 2109 |
+
await cl.Message(
|
| 2110 |
+
content=result[1][0][1]
|
| 2111 |
+
|
| 2112 |
+
).send()
|
| 2113 |
+
|
| 2114 |
+
elif chat_profile == 'Qwen1.5-32B':
|
| 2115 |
+
client = Client("Qwen/Qwen1.5-32B-Chat-demo", hf_token=hf_token)
|
| 2116 |
+
result = client.predict(
|
| 2117 |
+
query=message.content,
|
| 2118 |
+
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2119 |
+
api_name="/model_chat"
|
| 2120 |
+
)
|
| 2121 |
+
await cl.Message(
|
| 2122 |
+
content=result[1][0][1]
|
| 2123 |
+
|
| 2124 |
+
).send()
|
| 2125 |
+
|
| 2126 |
+
elif chat_profile == 'Qwen1.5-2.7B':
|
| 2127 |
+
client = Client("Qwen/qwen1.5-MoE-A2.7B-Chat-demo", hf_token=hf_token)
|
| 2128 |
+
result = client.predict(
|
| 2129 |
+
query=message.content,
|
| 2130 |
+
system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2131 |
+
api_name="/model_chat"
|
| 2132 |
+
)
|
| 2133 |
+
await cl.Message(
|
| 2134 |
+
content=result[1][0][1]
|
| 2135 |
+
|
| 2136 |
+
).send()
|
| 2137 |
+
|
| 2138 |
+
# elif chat_profile == 'Qwen-14B':
|
| 2139 |
+
# client = Client("Qwen/qwen1.5-MoE-A2.7B-Chat-demo", hf_token=hf_token)
|
| 2140 |
+
# result = client.predict(
|
| 2141 |
+
# query=message.content,
|
| 2142 |
+
# system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2143 |
+
# api_name="/model_chat"
|
| 2144 |
+
# )
|
| 2145 |
+
# await cl.Message(
|
| 2146 |
+
# content=result[1][0][1]
|
| 2147 |
+
|
| 2148 |
+
# ).send()
|
| 2149 |
+
|
| 2150 |
+
# elif chat_profile == 'Qwen-7B':
|
| 2151 |
+
# client = Client("Qwen/qwen1.5-MoE-A2.7B-Chat-demo", hf_token=hf_token)
|
| 2152 |
+
# result = client.predict(
|
| 2153 |
+
# query=message.content,
|
| 2154 |
+
# system="You are a helpful AI chatbot made by two iranian boys named Artin Daneshvar and Sadra Noadoust",
|
| 2155 |
+
# api_name="/model_chat"
|
| 2156 |
+
# )
|
| 2157 |
+
# await cl.Message(
|
| 2158 |
+
# content=result[1][0][1]
|
| 2159 |
+
|
| 2160 |
+
# ).send()
|
| 2161 |
+
|
| 2162 |
+
elif chat_profile == 'Llama-3.1-405B':
|
| 2163 |
+
completion = groq_client.chat.completions.create(
|
| 2164 |
+
model="llama-3.1-405b-reasoning",
|
| 2165 |
+
messages=[
|
| 2166 |
+
{
|
| 2167 |
+
"role": "user",
|
| 2168 |
+
"content": message.content
|
| 2169 |
+
}
|
| 2170 |
+
],
|
| 2171 |
+
temperature=1,
|
| 2172 |
+
max_tokens=1024,
|
| 2173 |
+
top_p=1,
|
| 2174 |
+
stream=True,
|
| 2175 |
+
stop=None,
|
| 2176 |
+
)
|
| 2177 |
|
| 2178 |
+
complete_content = ""
|
| 2179 |
+
|
| 2180 |
+
# Iterate over each chunk
|
| 2181 |
+
for chunk in completion:
|
| 2182 |
+
# Retrieve the content from the current chunk
|
| 2183 |
+
content = chunk.choices[0].delta.content
|
| 2184 |
+
|
| 2185 |
+
# Check if the content is not None before concatenating it
|
| 2186 |
+
if content is not None:
|
| 2187 |
+
complete_content += content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2188 |
|
| 2189 |
+
# Send the concatenated content as a message
|
| 2190 |
+
await cl.Message(content=complete_content).send()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2191 |
|
| 2192 |
+
|
| 2193 |
+
elif chat_profile == 'Llama-3.1-70B':
|
| 2194 |
+
completion = groq_client.chat.completions.create(
|
| 2195 |
+
model="llama-3.1-70b-versatile",
|
| 2196 |
+
messages=[
|
| 2197 |
+
{
|
| 2198 |
+
"role": "user",
|
| 2199 |
+
"content": message.content
|
| 2200 |
+
}
|
| 2201 |
+
],
|
| 2202 |
+
temperature=1,
|
| 2203 |
+
max_tokens=1024,
|
| 2204 |
+
top_p=1,
|
| 2205 |
+
stream=True,
|
| 2206 |
+
stop=None,
|
| 2207 |
+
)
|
| 2208 |
+
|
| 2209 |
+
complete_content = ""
|
| 2210 |
+
|
| 2211 |
+
# Iterate over each chunk
|
| 2212 |
+
for chunk in completion:
|
| 2213 |
+
# Retrieve the content from the current chunk
|
| 2214 |
+
content = chunk.choices[0].delta.content
|
| 2215 |
+
|
| 2216 |
+
# Check if the content is not None before concatenating it
|
| 2217 |
+
if content is not None:
|
| 2218 |
+
complete_content += content
|
| 2219 |
+
|
| 2220 |
+
# Send the concatenated content as a message
|
| 2221 |
+
await cl.Message(content=complete_content).send()
|
| 2222 |
|
| 2223 |
+
elif chat_profile == 'Llama-3.1-8B':
|
| 2224 |
+
completion = groq_client.chat.completions.create(
|
| 2225 |
+
model="llama-3.1-8b-instant",
|
| 2226 |
+
messages=[
|
| 2227 |
+
{
|
| 2228 |
+
"role": "user",
|
| 2229 |
+
"content": message.content
|
| 2230 |
+
}
|
| 2231 |
+
],
|
| 2232 |
+
temperature=1,
|
| 2233 |
+
max_tokens=1024,
|
| 2234 |
+
top_p=1,
|
| 2235 |
+
stream=True,
|
| 2236 |
+
stop=None,
|
| 2237 |
+
)
|
| 2238 |
+
|
| 2239 |
+
complete_content = ""
|
| 2240 |
+
|
| 2241 |
+
# Iterate over each chunk
|
| 2242 |
+
for chunk in completion:
|
| 2243 |
+
# Retrieve the content from the current chunk
|
| 2244 |
+
content = chunk.choices[0].delta.content
|
| 2245 |
+
|
| 2246 |
+
# Check if the content is not None before concatenating it
|
| 2247 |
+
if content is not None:
|
| 2248 |
+
complete_content += content
|
| 2249 |
+
|
| 2250 |
+
# Send the concatenated content as a message
|
| 2251 |
+
await cl.Message(content=complete_content).send()
|
| 2252 |
|
| 2253 |
+
elif chat_profile == 'Llama-3-70B':
|
| 2254 |
+
completion = groq_client.chat.completions.create(
|
| 2255 |
+
model="llama3-70b-8192",
|
| 2256 |
+
messages=[
|
| 2257 |
+
{
|
| 2258 |
+
"role": "user",
|
| 2259 |
+
"content": message.content
|
| 2260 |
+
}
|
| 2261 |
+
],
|
| 2262 |
+
temperature=1,
|
| 2263 |
+
max_tokens=1024,
|
| 2264 |
+
top_p=1,
|
| 2265 |
+
stream=True,
|
| 2266 |
+
stop=None,
|
| 2267 |
+
)
|
| 2268 |
|
| 2269 |
+
complete_content = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2270 |
|
| 2271 |
+
# Iterate over each chunk
|
| 2272 |
+
for chunk in completion:
|
| 2273 |
+
# Retrieve the content from the current chunk
|
| 2274 |
+
content = chunk.choices[0].delta.content
|
| 2275 |
+
|
| 2276 |
+
# Check if the content is not None before concatenating it
|
| 2277 |
+
if content is not None:
|
| 2278 |
+
complete_content += content
|
| 2279 |
|
| 2280 |
+
# Send the concatenated content as a message
|
| 2281 |
+
await cl.Message(content=complete_content).send()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2282 |
|
| 2283 |
+
elif chat_profile == 'Llama-3-8B':
|
| 2284 |
+
completion = groq_client.chat.completions.create(
|
| 2285 |
+
model="llama3-8b-8192",
|
| 2286 |
+
messages=[
|
| 2287 |
+
{
|
| 2288 |
+
"role": "user",
|
| 2289 |
+
"content": message.content
|
| 2290 |
+
}
|
| 2291 |
+
],
|
| 2292 |
+
temperature=1,
|
| 2293 |
+
max_tokens=1024,
|
| 2294 |
+
top_p=1,
|
| 2295 |
+
stream=True,
|
| 2296 |
+
stop=None,
|
| 2297 |
+
)
|
|
|
|
|
|
|
|
|
|
| 2298 |
|
| 2299 |
+
complete_content = ""
|
| 2300 |
|
| 2301 |
+
# Iterate over each chunk
|
| 2302 |
+
for chunk in completion:
|
| 2303 |
+
# Retrieve the content from the current chunk
|
| 2304 |
+
content = chunk.choices[0].delta.content
|
| 2305 |
+
|
| 2306 |
+
# Check if the content is not None before concatenating it
|
| 2307 |
+
if content is not None:
|
| 2308 |
+
complete_content += content
|
| 2309 |
|
| 2310 |
+
# Send the concatenated content as a message
|
| 2311 |
+
await cl.Message(content=complete_content).send()
|
| 2312 |
+
|
| 2313 |
+
elif chat_profile == 'gemma2-9B':
|
| 2314 |
+
completion = groq_client.chat.completions.create(
|
| 2315 |
+
model="gemma2-9b-it",
|
| 2316 |
+
messages=[
|
| 2317 |
+
{
|
| 2318 |
+
"role": "user",
|
| 2319 |
+
"content": message.content
|
| 2320 |
+
}
|
| 2321 |
+
],
|
| 2322 |
+
temperature=1,
|
| 2323 |
+
max_tokens=1024,
|
| 2324 |
+
top_p=1,
|
| 2325 |
+
stream=True,
|
| 2326 |
+
stop=None,
|
| 2327 |
+
)
|
| 2328 |
+
|
| 2329 |
+
complete_content = ""
|
| 2330 |
+
|
| 2331 |
+
# Iterate over each chunk
|
| 2332 |
+
for chunk in completion:
|
| 2333 |
+
# Retrieve the content from the current chunk
|
| 2334 |
+
content = chunk.choices[0].delta.content
|
| 2335 |
+
|
| 2336 |
+
# Check if the content is not None before concatenating it
|
| 2337 |
+
if content is not None:
|
| 2338 |
+
complete_content += content
|
| 2339 |
+
|
| 2340 |
+
# Send the concatenated content as a message
|
| 2341 |
+
await cl.Message(content=complete_content).send()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2342 |
|
| 2343 |
+
elif chat_profile == 'gemma-7B':
|
| 2344 |
+
completion = groq_client.chat.completions.create(
|
| 2345 |
+
model="gemma-7b-it",
|
| 2346 |
+
messages=[
|
| 2347 |
+
{
|
| 2348 |
+
"role": "user",
|
| 2349 |
+
"content": message.content
|
| 2350 |
+
}
|
| 2351 |
+
],
|
| 2352 |
+
temperature=1,
|
| 2353 |
+
max_tokens=1024,
|
| 2354 |
+
top_p=1,
|
| 2355 |
+
stream=True,
|
| 2356 |
+
stop=None,
|
| 2357 |
+
)
|
| 2358 |
+
|
| 2359 |
+
complete_content = ""
|
| 2360 |
+
|
| 2361 |
+
# Iterate over each chunk
|
| 2362 |
+
for chunk in completion:
|
| 2363 |
+
# Retrieve the content from the current chunk
|
| 2364 |
+
content = chunk.choices[0].delta.content
|
| 2365 |
+
|
| 2366 |
+
# Check if the content is not None before concatenating it
|
| 2367 |
+
if content is not None:
|
| 2368 |
+
complete_content += content
|
| 2369 |
+
|
| 2370 |
+
# Send the concatenated content as a message
|
| 2371 |
+
await cl.Message(content=complete_content).send()
|
| 2372 |
+
|
| 2373 |
+
elif chat_profile == "zephyr-7B":
|
| 2374 |
+
result = hf_text_client.predict(
|
| 2375 |
+
message=message.content,
|
| 2376 |
+
request="your name is zephyr,An AI Assistant designed by neural nexus team. i was made by Artin Daneshvar and Sadra Noadoust, 2 iranian students!",
|
| 2377 |
+
param_3=512,
|
| 2378 |
+
param_4=0.7,
|
| 2379 |
+
param_5=0.95,
|
| 2380 |
+
api_name="/chat"
|
| 2381 |
+
)
|
| 2382 |
+
model_response = result.strip("</s>")
|
| 2383 |
+
await cl.Message(
|
| 2384 |
+
content=model_response
|
| 2385 |
+
).send()
|
| 2386 |
+
|
| 2387 |
+
elif chat_profile == 'mixtral-8x7B':
|
| 2388 |
+
completion = groq_client.chat.completions.create(
|
| 2389 |
+
model="mixtral-8x7b-32768",
|
| 2390 |
+
messages=[
|
| 2391 |
+
{
|
| 2392 |
+
"role": "user",
|
| 2393 |
+
"content": message.content
|
| 2394 |
+
}
|
| 2395 |
+
],
|
| 2396 |
+
temperature=1,
|
| 2397 |
+
max_tokens=1024,
|
| 2398 |
+
top_p=1,
|
| 2399 |
+
stream=True,
|
| 2400 |
+
stop=None,
|
| 2401 |
+
)
|
| 2402 |
+
|
| 2403 |
+
complete_content = ""
|
| 2404 |
+
|
| 2405 |
+
for chunk in completion:
|
| 2406 |
+
content = chunk.choices[0].delta.content
|
| 2407 |
+
|
| 2408 |
+
if content is not None:
|
| 2409 |
+
complete_content += content
|
| 2410 |
+
|
| 2411 |
+
await cl.Message(content=complete_content).send()
|
| 2412 |
+
|
| 2413 |
+
elif chat_profile == 'mistral-nemo-12B':
|
| 2414 |
+
client = Client("0x7o/Mistral-Nemo-Instruct", hf_token=hf_token)
|
| 2415 |
+
result = client.predict(
|
| 2416 |
+
message=message.content,
|
| 2417 |
+
max_new_tokens=512,
|
| 2418 |
+
temperature=0.7,
|
| 2419 |
+
top_p=0.95,
|
| 2420 |
+
api_name="/chat"
|
| 2421 |
+
)
|
| 2422 |
+
await cl.Message(
|
| 2423 |
+
content=result[1][0][1]
|
| 2424 |
+
|
| 2425 |
+
).send()
|
| 2426 |
+
|
| 2427 |
+
# elif chat_profile == 'Toka-353M':
|
| 2428 |
+
# output = query({
|
| 2429 |
+
# "inputs": message.content,
|
| 2430 |
+
# })
|
| 2431 |
+
# await cl.Message(
|
| 2432 |
+
# content=output[0]['sequence']
|
| 2433 |
+
# ).send()
|
| 2434 |
+
|
| 2435 |
+
elif chat_profile == 'Aya-23B':
|
| 2436 |
+
stream = co.chat_stream(
|
| 2437 |
+
model='c4ai-aya-23',
|
| 2438 |
message=message.content,
|
| 2439 |
+
temperature=0.3,
|
| 2440 |
+
# chat_history=[{"role": "User", "message": "Hello"}, {"role": "Chatbot", "message": "Hello! How can I help you today?"}, {"role": "User", "message": "Hi"}, {"role": "User", "message": "hello"}],
|
| 2441 |
+
prompt_truncation='OFF',
|
| 2442 |
+
connectors=[],
|
| 2443 |
+
)
|
| 2444 |
+
|
| 2445 |
+
complete_content = ''
|
| 2446 |
+
for event in stream:
|
| 2447 |
+
if event.event_type == 'text-generation':
|
| 2448 |
+
complete_content += event.text
|
| 2449 |
+
await cl.Message(content=complete_content).send()
|
| 2450 |
+
|
| 2451 |
+
elif chat_profile == 'Aya-35B':
|
| 2452 |
+
stream = co.chat_stream(
|
| 2453 |
+
model='c4ai-aya-23',
|
| 2454 |
+
message=message.content,
|
| 2455 |
+
temperature=0.3,
|
| 2456 |
+
# chat_history=[{"role": "User", "message": "Hello"}, {"role": "Chatbot", "message": "Hello! How can I help you today?"}, {"role": "User", "message": "Hi"}, {"role": "User", "message": "hello"}],
|
| 2457 |
+
prompt_truncation='OFF',
|
| 2458 |
+
connectors=[],
|
| 2459 |
+
)
|
| 2460 |
+
|
| 2461 |
+
complete_content = ''
|
| 2462 |
+
for event in stream:
|
| 2463 |
+
if event.event_type == 'text-generation':
|
| 2464 |
+
complete_content += event.text
|
| 2465 |
+
await cl.Message(content=complete_content).send()
|
| 2466 |
+
|
| 2467 |
+
elif chat_profile == 'Command-R-Plus':
|
| 2468 |
+
stream = co.chat_stream(
|
| 2469 |
+
model='command-r-plus',
|
| 2470 |
+
message=message.content,
|
| 2471 |
+
temperature=0.3,
|
| 2472 |
+
chat_history=[],
|
| 2473 |
+
prompt_truncation='AUTO',
|
| 2474 |
+
)
|
| 2475 |
+
complete_content = ''
|
| 2476 |
+
for event in stream:
|
| 2477 |
+
if event.event_type == 'text-generation':
|
| 2478 |
+
complete_content += event.text
|
| 2479 |
+
await cl.Message(content=complete_content).send()
|
| 2480 |
+
|
| 2481 |
+
elif chat_profile == 'Command-R':
|
| 2482 |
+
stream = co.chat_stream(
|
| 2483 |
+
model='command-r',
|
| 2484 |
+
message=message.content,
|
| 2485 |
+
temperature=0.3,
|
| 2486 |
+
chat_history=[],
|
| 2487 |
+
prompt_truncation='AUTO',
|
| 2488 |
+
)
|
| 2489 |
+
complete_content = ''
|
| 2490 |
+
for event in stream:
|
| 2491 |
+
if event.event_type == 'text-generation':
|
| 2492 |
+
complete_content += event.text
|
| 2493 |
+
await cl.Message(content=complete_content).send()
|
| 2494 |
+
|
| 2495 |
+
elif chat_profile == 'Command':
|
| 2496 |
+
stream = co.chat_stream(
|
| 2497 |
+
model='command',
|
| 2498 |
+
message=message.content,
|
| 2499 |
+
temperature=0.3,
|
| 2500 |
+
chat_history=[],
|
| 2501 |
+
prompt_truncation='AUTO',
|
| 2502 |
+
)
|
| 2503 |
+
complete_content = ''
|
| 2504 |
+
for event in stream:
|
| 2505 |
+
if event.event_type == 'text-generation':
|
| 2506 |
+
complete_content += event.text
|
| 2507 |
+
await cl.Message(content=complete_content).send()
|
| 2508 |
|
| 2509 |
+
elif chat_profile == 'Command-Light':
|
| 2510 |
+
stream = co.chat_stream(
|
| 2511 |
+
model='command-light',
|
| 2512 |
+
message=message.content,
|
| 2513 |
+
temperature=0.3,
|
| 2514 |
+
chat_history=[],
|
| 2515 |
+
prompt_truncation='AUTO',
|
| 2516 |
+
)
|
| 2517 |
+
complete_content = ''
|
| 2518 |
+
for event in stream:
|
| 2519 |
+
if event.event_type == 'text-generation':
|
| 2520 |
+
complete_content += event.text
|
| 2521 |
+
await cl.Message(content=complete_content).send()
|
| 2522 |
+
|
| 2523 |
+
elif chat_profile == 'Command-Light-Nightly':
|
| 2524 |
+
stream = co.chat_stream(
|
| 2525 |
+
model='command-light-nightly',
|
| 2526 |
+
message=message.content,
|
| 2527 |
+
temperature=0.3,
|
| 2528 |
+
chat_history=[],
|
| 2529 |
+
prompt_truncation='AUTO',
|
| 2530 |
+
)
|
| 2531 |
+
complete_content = ''
|
| 2532 |
+
for event in stream:
|
| 2533 |
+
if event.event_type == 'text-generation':
|
| 2534 |
+
complete_content += event.text
|
| 2535 |
+
await cl.Message(content=complete_content).send()
|
| 2536 |
+
|
| 2537 |
+
elif chat_profile == 'Command-Nightly':
|
| 2538 |
+
stream = co.chat_stream(
|
| 2539 |
+
model='command-light-nightly',
|
| 2540 |
+
message=message.content,
|
| 2541 |
+
temperature=0.3,
|
| 2542 |
+
chat_history=[],
|
| 2543 |
+
prompt_truncation='AUTO',
|
| 2544 |
+
)
|
| 2545 |
+
complete_content = ''
|
| 2546 |
+
for event in stream:
|
| 2547 |
+
if event.event_type == 'text-generation':
|
| 2548 |
+
complete_content += event.text
|
| 2549 |
+
await cl.Message(content=complete_content).send()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2550 |
|
| 2551 |
@cl.on_settings_update
|
| 2552 |
async def setup_agent(settings):
|