mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Merge branch 'master' of github.com:khoj-ai/khoj into features/update-home-page
This commit is contained in:
@@ -9,7 +9,7 @@ export function ContentSecurityPolicy() {
|
|||||||
style-src 'self' https://assets.khoj.dev 'unsafe-inline' https://fonts.googleapis.com https://accounts.google.com;
|
style-src 'self' https://assets.khoj.dev 'unsafe-inline' https://fonts.googleapis.com https://accounts.google.com;
|
||||||
img-src 'self' data: blob: https://*.khoj.dev https://accounts.google.com https://*.googleusercontent.com https://*.google.com/ https://*.gstatic.com;
|
img-src 'self' data: blob: https://*.khoj.dev https://accounts.google.com https://*.googleusercontent.com https://*.google.com/ https://*.gstatic.com;
|
||||||
font-src 'self' https://assets.khoj.dev https://fonts.gstatic.com;
|
font-src 'self' https://assets.khoj.dev https://fonts.gstatic.com;
|
||||||
frame-src 'self' https://accounts.google.com;
|
frame-src 'self' https://accounts.google.com https://app.chatwoot.com;
|
||||||
child-src 'self' https://app.chatwoot.com;
|
child-src 'self' https://app.chatwoot.com;
|
||||||
object-src 'none';"
|
object-src 'none';"
|
||||||
></meta>
|
></meta>
|
||||||
|
|||||||
@@ -58,13 +58,17 @@ def completion_with_backoff(
|
|||||||
openai_clients[client_key] = client
|
openai_clients[client_key] = client
|
||||||
|
|
||||||
formatted_messages = [{"role": message.role, "content": message.content} for message in messages]
|
formatted_messages = [{"role": message.role, "content": message.content} for message in messages]
|
||||||
stream = True
|
|
||||||
|
|
||||||
# Update request parameters for compatability with o1 model series
|
# Update request parameters for compatability with o1 model series
|
||||||
# Refer: https://platform.openai.com/docs/guides/reasoning/beta-limitations
|
# Refer: https://platform.openai.com/docs/guides/reasoning/beta-limitations
|
||||||
if model_name.startswith("o1"):
|
stream = True
|
||||||
|
model_kwargs["stream_options"] = {"include_usage": True}
|
||||||
|
if model_name == "o1":
|
||||||
|
temperature = 1
|
||||||
|
stream = False
|
||||||
|
model_kwargs.pop("stream_options", None)
|
||||||
|
elif model_name.startswith("o1"):
|
||||||
temperature = 1
|
temperature = 1
|
||||||
model_kwargs.pop("stop", None)
|
|
||||||
model_kwargs.pop("response_format", None)
|
model_kwargs.pop("response_format", None)
|
||||||
|
|
||||||
if os.getenv("KHOJ_LLM_SEED"):
|
if os.getenv("KHOJ_LLM_SEED"):
|
||||||
@@ -74,7 +78,6 @@ def completion_with_backoff(
|
|||||||
messages=formatted_messages, # type: ignore
|
messages=formatted_messages, # type: ignore
|
||||||
model=model_name, # type: ignore
|
model=model_name, # type: ignore
|
||||||
stream=stream,
|
stream=stream,
|
||||||
stream_options={"include_usage": True} if stream else {},
|
|
||||||
temperature=temperature,
|
temperature=temperature,
|
||||||
timeout=20,
|
timeout=20,
|
||||||
**model_kwargs,
|
**model_kwargs,
|
||||||
@@ -165,13 +168,17 @@ def llm_thread(
|
|||||||
client = openai_clients[client_key]
|
client = openai_clients[client_key]
|
||||||
|
|
||||||
formatted_messages = [{"role": message.role, "content": message.content} for message in messages]
|
formatted_messages = [{"role": message.role, "content": message.content} for message in messages]
|
||||||
stream = True
|
|
||||||
|
|
||||||
# Update request parameters for compatability with o1 model series
|
# Update request parameters for compatability with o1 model series
|
||||||
# Refer: https://platform.openai.com/docs/guides/reasoning/beta-limitations
|
# Refer: https://platform.openai.com/docs/guides/reasoning/beta-limitations
|
||||||
if model_name.startswith("o1"):
|
stream = True
|
||||||
|
model_kwargs["stream_options"] = {"include_usage": True}
|
||||||
|
if model_name == "o1":
|
||||||
|
temperature = 1
|
||||||
|
stream = False
|
||||||
|
model_kwargs.pop("stream_options", None)
|
||||||
|
elif model_name.startswith("o1-"):
|
||||||
temperature = 1
|
temperature = 1
|
||||||
model_kwargs.pop("stop", None)
|
|
||||||
model_kwargs.pop("response_format", None)
|
model_kwargs.pop("response_format", None)
|
||||||
|
|
||||||
if os.getenv("KHOJ_LLM_SEED"):
|
if os.getenv("KHOJ_LLM_SEED"):
|
||||||
@@ -181,7 +188,6 @@ def llm_thread(
|
|||||||
messages=formatted_messages,
|
messages=formatted_messages,
|
||||||
model=model_name, # type: ignore
|
model=model_name, # type: ignore
|
||||||
stream=stream,
|
stream=stream,
|
||||||
stream_options={"include_usage": True} if stream else {},
|
|
||||||
temperature=temperature,
|
temperature=temperature,
|
||||||
timeout=20,
|
timeout=20,
|
||||||
**model_kwargs,
|
**model_kwargs,
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ from khoj.search_filter.word_filter import WordFilter
|
|||||||
from khoj.utils import state
|
from khoj.utils import state
|
||||||
from khoj.utils.helpers import (
|
from khoj.utils.helpers import (
|
||||||
ConversationCommand,
|
ConversationCommand,
|
||||||
in_debug_mode,
|
|
||||||
is_none_or_empty,
|
is_none_or_empty,
|
||||||
is_promptrace_enabled,
|
is_promptrace_enabled,
|
||||||
merge_dicts,
|
merge_dicts,
|
||||||
@@ -47,28 +46,27 @@ logger = logging.getLogger(__name__)
|
|||||||
try:
|
try:
|
||||||
from git import Repo
|
from git import Repo
|
||||||
except ImportError:
|
except ImportError:
|
||||||
if in_debug_mode():
|
if is_promptrace_enabled():
|
||||||
logger.warning("GitPython not installed. `pip install gitpython` to enable prompt tracer.")
|
logger.warning("GitPython not installed. `pip install gitpython` to use prompt tracer.")
|
||||||
|
|
||||||
model_to_prompt_size = {
|
model_to_prompt_size = {
|
||||||
# OpenAI Models
|
# OpenAI Models
|
||||||
"gpt-4o": 20000,
|
"gpt-4o": 60000,
|
||||||
"gpt-4o-mini": 20000,
|
"gpt-4o-mini": 60000,
|
||||||
"o1-preview": 20000,
|
"o1": 20000,
|
||||||
"o1-mini": 20000,
|
"o1-mini": 60000,
|
||||||
# Google Models
|
# Google Models
|
||||||
"gemini-1.5-flash": 20000,
|
"gemini-1.5-flash": 60000,
|
||||||
"gemini-1.5-pro": 20000,
|
"gemini-1.5-pro": 60000,
|
||||||
# Anthropic Models
|
# Anthropic Models
|
||||||
"claude-3-5-sonnet-20241022": 20000,
|
"claude-3-5-sonnet-20241022": 60000,
|
||||||
"claude-3-5-haiku-20241022": 20000,
|
"claude-3-5-haiku-20241022": 60000,
|
||||||
# Offline Models
|
# Offline Models
|
||||||
"bartowski/Meta-Llama-3.1-8B-Instruct-GGUF": 20000,
|
"Qwen/Qwen2.5-14B-Instruct-GGUF": 20000,
|
||||||
"bartowski/Meta-Llama-3.1-8B-Instruct-GGUF": 20000,
|
"bartowski/Meta-Llama-3.1-8B-Instruct-GGUF": 20000,
|
||||||
"bartowski/Llama-3.2-3B-Instruct-GGUF": 20000,
|
"bartowski/Llama-3.2-3B-Instruct-GGUF": 20000,
|
||||||
"bartowski/gemma-2-9b-it-GGUF": 6000,
|
"bartowski/gemma-2-9b-it-GGUF": 6000,
|
||||||
"bartowski/gemma-2-2b-it-GGUF": 6000,
|
"bartowski/gemma-2-2b-it-GGUF": 6000,
|
||||||
"Qwen/Qwen2.5-14B-Instruct-GGUF": 20000,
|
|
||||||
}
|
}
|
||||||
model_to_tokenizer: Dict[str, str] = {}
|
model_to_tokenizer: Dict[str, str] = {}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ model_to_cost: Dict[str, Dict[str, float]] = {
|
|||||||
# OpenAI Pricing: https://openai.com/api/pricing/
|
# OpenAI Pricing: https://openai.com/api/pricing/
|
||||||
"gpt-4o": {"input": 2.50, "output": 10.00},
|
"gpt-4o": {"input": 2.50, "output": 10.00},
|
||||||
"gpt-4o-mini": {"input": 0.15, "output": 0.60},
|
"gpt-4o-mini": {"input": 0.15, "output": 0.60},
|
||||||
"o1-preview": {"input": 15.0, "output": 60.00},
|
"o1": {"input": 15.0, "output": 60.00},
|
||||||
"o1-mini": {"input": 3.0, "output": 12.0},
|
"o1-mini": {"input": 3.0, "output": 12.0},
|
||||||
# Gemini Pricing: https://ai.google.dev/pricing
|
# Gemini Pricing: https://ai.google.dev/pricing
|
||||||
"gemini-1.5-flash": {"input": 0.075, "output": 0.30},
|
"gemini-1.5-flash": {"input": 0.075, "output": 0.30},
|
||||||
|
|||||||
Reference in New Issue
Block a user