fixed bug related to not given config
This commit is contained in:
parent
6a9f4ce203
commit
4dc355b2cb
22
project.py
22
project.py
|
@ -31,14 +31,9 @@ def main():
|
||||||
elif config["mode"] == "terminal":
|
elif config["mode"] == "terminal":
|
||||||
handle_terminal(args)
|
handle_terminal(args)
|
||||||
elif config["mode"] == "gui":
|
elif config["mode"] == "gui":
|
||||||
try:
|
|
||||||
config["ollamaConfig"]["base_header"] = json.loads(config["ollamaConfig"]["base_header"])
|
|
||||||
config["ollamaConfig"]["embeddings_header"] = json.loads(config["ollamaConfig"]["embeddings_header"])
|
|
||||||
except json.decoder.JSONDecodeError:
|
|
||||||
"""can be ignored if no header needed"""
|
|
||||||
pass
|
|
||||||
# start gui
|
# start gui
|
||||||
try:
|
try:
|
||||||
|
print(config["ollamaConfig"]["embeddings_header"] )
|
||||||
gui = ChatGUI(**config["ollamaConfig"])
|
gui = ChatGUI(**config["ollamaConfig"])
|
||||||
gui.mainloop()
|
gui.mainloop()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
@ -58,11 +53,14 @@ def configure():
|
||||||
embeddings_url = input("Enter embeddings URL (standard: http://localhost:11434): ") or "http://localhost:11434"
|
embeddings_url = input("Enter embeddings URL (standard: http://localhost:11434): ") or "http://localhost:11434"
|
||||||
base_model = input("Enter base model (standard: 'mistral'): ") or "mistral"
|
base_model = input("Enter base model (standard: 'mistral'): ") or "mistral"
|
||||||
embeddings_model = input("Enter embeddings model (standard: 'mxbai-embed-large'): ") or "mxbai-embed-large"
|
embeddings_model = input("Enter embeddings model (standard: 'mxbai-embed-large'): ") or "mxbai-embed-large"
|
||||||
base_header = input("Authentication for base model (standard: empty): ") or ""
|
base_header_key = input("Authentication Key for base model (standard: empty): ") or ""
|
||||||
embeddings_header = input("Authentication for embeddings model (standard: empty): ") or ""
|
base_header_value = input("Authentication Value for base model (standard: empty): ") or ""
|
||||||
|
embeddings_header_key = input("Authentication Key for embeddings model (standard: empty): ") or ""
|
||||||
|
embeddings_header_value = input("Authentication Value for embeddings model (standard: empty): ") or ""
|
||||||
|
|
||||||
return {"mode": mode, "ollamaConfig":{"base_url": base_llm_url, "embeddings_url": embeddings_url, "base_model": base_model,
|
return {"mode": mode, "ollamaConfig":{"base_url": base_llm_url, "embeddings_url": embeddings_url, "base_model": base_model,
|
||||||
"embeddings_model": embeddings_model, "base_header": base_header, "embeddings_header": embeddings_header}}
|
"embeddings_model": embeddings_model, "base_header":{base_header_key: base_header_value}
|
||||||
|
,"embeddings_header" :{embeddings_header_key: embeddings_header_value}}}
|
||||||
|
|
||||||
def read_config():
|
def read_config():
|
||||||
if not os.path.exists(CONFIG_FILE):
|
if not os.path.exists(CONFIG_FILE):
|
||||||
|
@ -88,12 +86,6 @@ def handle_change_mode(args):
|
||||||
|
|
||||||
def handle_terminal(args):
|
def handle_terminal(args):
|
||||||
config = read_config()
|
config = read_config()
|
||||||
try:
|
|
||||||
config["ollamaConfig"]["base_header"] = json.loads(config["ollamaConfig"]["base_header"])
|
|
||||||
config["ollamaConfig"]["embeddings_header"] = json.loads(config["ollamaConfig"]["embeddings_header"])
|
|
||||||
except json.decoder.JSONDecodeError:
|
|
||||||
"""can be ignored if no header needed"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
if args.p:
|
if args.p:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -27,4 +27,7 @@ class OllamaChatBot:
|
||||||
messanges = messanges[:5]
|
messanges = messanges[:5]
|
||||||
else:
|
else:
|
||||||
messanges = self.messanges
|
messanges = self.messanges
|
||||||
|
try:
|
||||||
return self.ollama.invoke(messanges).content
|
return self.ollama.invoke(messanges).content
|
||||||
|
except ValueError:
|
||||||
|
return "An unexpected Error occuried"
|
||||||
|
|
|
@ -10,17 +10,9 @@ CONFIG_FILE = 'tests/config.json'
|
||||||
def setup_config():
|
def setup_config():
|
||||||
"""Fixture to create a dummy config file before each test and remove it after."""
|
"""Fixture to create a dummy config file before each test and remove it after."""
|
||||||
# Create the config file
|
# Create the config file
|
||||||
initial_config = {
|
initial_config = {"mode": "terminal",
|
||||||
"mode": "terminal",
|
"ollamaConfig":{"base_url": 'https://ai.fabelous.app/v1/ollama/generic', "embeddings_url": 'http://localhost:11434', "base_model": 'mistral',
|
||||||
"ollamaConfig": {
|
"embeddings_model": 'mxbai-embed-large', "base_header":{'': ''},"" :{'': ''}}}
|
||||||
"base_url": "http://localhost:11434",
|
|
||||||
"embeddings_url": "http://localhost:11434",
|
|
||||||
"base_model": "mistral",
|
|
||||||
"embeddings_model": "mxbai-embed-large",
|
|
||||||
"base_header": "",
|
|
||||||
"embeddings_header": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
with open(CONFIG_FILE, 'w') as f:
|
with open(CONFIG_FILE, 'w') as f:
|
||||||
json.dump(initial_config, f)
|
json.dump(initial_config, f)
|
||||||
|
|
||||||
|
@ -38,8 +30,10 @@ def test_configure(monkeypatch):
|
||||||
'http://localhost:11434', # Embeddings URL
|
'http://localhost:11434', # Embeddings URL
|
||||||
'mistral', # Base model
|
'mistral', # Base model
|
||||||
'mxbai-embed-large', # Embeddings model
|
'mxbai-embed-large', # Embeddings model
|
||||||
'{"Authorization": "Token xzy"}', # Base header for authentication
|
'Authorization', # Base Model authentication key
|
||||||
'{"Authorization": "Token xzy"}', # Embeddings header for authentication
|
'Token xzy', # Base Model authentication value
|
||||||
|
'Authorization', # Embeddings key for authentication
|
||||||
|
'Token xzy'# Embeddings value for authentication
|
||||||
])
|
])
|
||||||
|
|
||||||
monkeypatch.setattr('builtins.input', lambda _: next(inputs))
|
monkeypatch.setattr('builtins.input', lambda _: next(inputs))
|
||||||
|
@ -47,17 +41,11 @@ def test_configure(monkeypatch):
|
||||||
config = configure()
|
config = configure()
|
||||||
|
|
||||||
# Expected configurations based on the inputs
|
# Expected configurations based on the inputs
|
||||||
expected_config = {
|
expected_config = {"mode": "terminal",
|
||||||
"mode": "terminal",
|
"ollamaConfig":{"base_url": 'https://ai.fabelous.app/v1/ollama/generic', "embeddings_url": 'http://localhost:11434', "base_model": 'mistral',
|
||||||
"ollamaConfig": {
|
"embeddings_model": 'mxbai-embed-large', "base_header":{'Authorization': 'Token xzy'}
|
||||||
"base_url": "https://ai.fabelous.app/v1/ollama/generic",
|
,"embeddings_header" :{'Authorization': 'Token xzy'}}}
|
||||||
"embeddings_url": "http://localhost:11434",
|
|
||||||
"base_model": "mistral",
|
|
||||||
"embeddings_model": "mxbai-embed-large",
|
|
||||||
"base_header": '{"Authorization": "Token xzy"}',
|
|
||||||
"embeddings_header": '{"Authorization": "Token xzy"}'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert config['mode'] == expected_config['mode'], "Mode configuration does not match."
|
assert config['mode'] == expected_config['mode'], "Mode configuration does not match."
|
||||||
assert config['ollamaConfig'] == expected_config['ollamaConfig'], "OllamaConfig does not match."
|
assert config['ollamaConfig'] == expected_config['ollamaConfig'], "OllamaConfig does not match."
|
||||||
|
|
Loading…
Reference in New Issue