You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to connect SQLserver or any database to send request to ollama and get an answer using the control on the dashboard...
i have some code to do that, but i don't how does it work?
import os
import pyodbc
import requests
from datetime import datetime
from typing import Dict
class Tools:
def init(self):
pass
if __name__ == "__main__":
# Ejemplo de uso
tools = Tools()
result = tools.get_connect_to_database()
print(result)
def get_connect_to_database(self, __user__: dict = {}) -> str:
"""
Testing...
"""
try:
server = __user__.get(
"server", os.getenv("DB_SERVER", "SQLSERVER")
)
database = __user__.get(
"database", os.getenv("DB_DATABASE", "myDBs")
)
username = __user__.get("username", os.getenv("DB_USERNAME", "users"))
password = __user__.get("password", os.getenv("DB_PASSWORD", "pass"))
if not all([server, username, password]):
raise ValueError("Missing required connection parameters")
connection_string = (
f"DRIVER={{ODBC Driver 17 for SQL Server}};"
f"SERVER={server};"
f"DATABASE={database};"
f"UID={username};"
f"PWD={password}"
)
conn = pyodbc.connect(connection_string)
print("Connection successful to the SQL Server database")
return "Connection successful"
except ValueError as ve:
return f"Error: {ve}"
except pyodbc.Error as ex:
return f"Database connection error: {ex}"
except Exception as e:
return f"An unexpected error occurred: {e}"
def get_user_name_and_email_and_id(self, __user__: dict = {}) -> str:
"""
Testing2...
"""
# Do not include :param for __user__ in the docstring as it should not be shown in the tool's specification
# The session user object will be passed as a parameter when the function is called
print(__user__)
result = ""
if "name" in __user__:
result += f"User: {__user__['name']}"
if "id" in __user__:
result += f" (ID: {__user__['id']})"
if "email" in __user__:
result += f" (Email: {__user__['email']})"
if result == "":
result = "User: Unknown"
return result
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I would like to connect SQLserver or any database to send request to ollama and get an answer using the control on the dashboard...
i have some code to do that, but i don't how does it work?
import os
import pyodbc
import requests
from datetime import datetime
from typing import Dict
class Tools:
def init(self):
pass
Beta Was this translation helpful? Give feedback.
All reactions