Improve the admin experience, add more metadata to the list_display

- Don't propagate max_tokens to the openai chat completion method. the max for the newer models is fixed at 4096 max output. The token limit is just used for input
This commit is contained in:
sabaimran 2024-05-27 00:49:20 +05:30
parent 01cdc54ad0
commit 9ebf3a4d80
4 changed files with 32 additions and 7 deletions

View file

@ -78,10 +78,8 @@ class KhojUserAdmin(UserAdmin):
admin.site.register(KhojUser, KhojUserAdmin)
admin.site.register(ChatModelOptions)
admin.site.register(ProcessLock)
admin.site.register(SpeechToTextModelOptions)
admin.site.register(OpenAIProcessorConversationConfig)
admin.site.register(SearchModelConfig)
admin.site.register(ReflectiveQuestion)
admin.site.register(UserSearchModelConfig)
@ -89,7 +87,6 @@ admin.site.register(TextToImageModelConfig)
admin.site.register(ClientApplication)
admin.site.register(GithubConfig)
admin.site.register(NotionConfig)
admin.site.register(ServerChatSettings)
@admin.register(Agent)
@ -131,6 +128,36 @@ class KhojUserSubscription(admin.ModelAdmin):
list_filter = ("type",)
@admin.register(ChatModelOptions)
class ChatModelOptionsAdmin(admin.ModelAdmin):
list_display = (
"id",
"chat_model",
"model_type",
"max_prompt_size",
)
search_fields = ("id", "chat_model", "model_type")
@admin.register(OpenAIProcessorConversationConfig)
class OpenAIProcessorConversationConfigAdmin(admin.ModelAdmin):
list_display = (
"id",
"name",
"api_key",
"api_base_url",
)
search_fields = ("id", "name", "api_key", "api_base_url")
@admin.register(ServerChatSettings)
class ServerChatSettingsAdmin(admin.ModelAdmin):
list_display = (
"default_model",
"summarizer_model",
)
@admin.register(Conversation)
class ConversationAdmin(admin.ModelAdmin):
list_display = (

View file

@ -67,7 +67,6 @@ def extract_questions(
messages=messages,
model=model,
temperature=temperature,
max_tokens=max_tokens,
api_base_url=api_base_url,
model_kwargs={"response_format": {"type": "json_object"}},
openai_api_key=api_key,

View file

@ -34,7 +34,7 @@ openai_clients: Dict[str, openai.OpenAI] = {}
reraise=True,
)
def completion_with_backoff(
messages, model, temperature=0, openai_api_key=None, api_base_url=None, model_kwargs=None, max_tokens=None
messages, model, temperature=0, openai_api_key=None, api_base_url=None, model_kwargs=None
) -> str:
client_key = f"{openai_api_key}--{api_base_url}"
client: openai.OpenAI = openai_clients.get(client_key)
@ -53,7 +53,6 @@ def completion_with_backoff(
model=model, # type: ignore
temperature=temperature,
timeout=20,
max_tokens=max_tokens,
**(model_kwargs or dict()),
)
aggregated_response = ""

View file

@ -993,7 +993,7 @@ def scheduled_chat(
# Stop if the chat API call was not successful
if raw_response.status_code != 200:
logger.error(f"Failed to run schedule chat: {raw_response.text}")
logger.error(f"Failed to run schedule chat: {raw_response.text}, user: {user}, query: {query_to_run}")
return None
# Extract the AI response from the chat API response