Skip to content

Commit

Permalink
fix: fix refer
Browse files Browse the repository at this point in the history
  • Loading branch information
seo-rii committed Aug 5, 2024
1 parent 3efaebb commit 4bb995c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
52 changes: 37 additions & 15 deletions frontend/src/lib/ChatBox.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<script lang="ts">
import {Button, CircularProgress, Icon, Input} from "nunui";
import {Button, CircularProgress, Icon, Input, List, OneLine, Option, Paper, Select} from "nunui";
import Expand from "$lib/Expand.svelte";
import {onMount, tick} from "svelte";
import api from "$utils/api";
import {browser} from "$app/environment";
import Provider from "$lib/Provider.svelte";
async function getAnswer(question: string): Promise<string> {
return (await api('/api/chat', {
refer: [],
refer: refer.map(i => +i.id).filter(x => x),
body: (title ? `${title} 논문을 특히 참고하여 대답해 줘. ` : '') + question,
id: Date.now(),
})) || '답변이 없어요.';
}
Expand All @@ -35,7 +37,7 @@
}
let focus = false, value = '', showHistory = false, container: HTMLElement;
let history = [];
let history = [], refer = [];
let clientHeight, title;
$: {
Expand All @@ -53,24 +55,44 @@
title = window.title;
}, 100);
})
function toggleRefer(id) {
return () => {
if (refer.includes(id)) refer = refer.filter(i => i !== id);
else refer = [...refer, id];
}
}
</script>

<div style:height="{clientHeight + 12}px"></div>
<main bind:clientHeight>
<Expand>
{#if true}
<div class="row" style="padding-bottom: 0">
<div style="width: 24px"></div>
<Button small outlined>
{#if title}
{title} 논문 위주 참고
{:else}
전체 파일 참고
{/if}
</Button>
<Button small outlined={!showHistory} on:click={() => showHistory = !showHistory} icon="history">대화 내역
</Button>
</div>
<Provider api="paper" let:data>
<div class="row" style="padding-bottom: 0">
<div style="width: 24px"></div>
<Paper left xstack top>
<Button small outlined slot="target">
{#if refer?.length}
{refer.length}개 논문 참고
{:else if title}
{title} 논문 위주 참고
{:else}
전체 파일 참고
{/if}
</Button>
<div style="padding: 12px">참고할 목록</div>
<List multiple bind:selected={refer}>
{#each data.list || [] as item}
<OneLine title={item.title} on:click={toggleRefer(item)} active={refer.includes(item)}/>
{/each}
</List>
</Paper>
<Button small outlined={!showHistory} on:click={() => showHistory = !showHistory} icon="history">대화
내역
</Button>
</div>
</Provider>
{/if}
</Expand>
<Expand>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {tick} from "svelte";
//@ts-ignore
import {get_current_component} from "svelte/internal";

export const endpoint = import.meta.env.DEV ? 'http://localhost:8000' : 'https://api-naddal.seorii.page'
export const endpoint = import.meta.env.DEV ? 'http://localhost:80' : 'https://api-naddal.seorii.page'

export default function api(path: string, data: any = undefined, method = 'POST'): Promise<any> {
if (!browser) return new Promise<{ data: any }>(() => null)
Expand Down
4 changes: 2 additions & 2 deletions server/paper_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def chat(chat_request: ChatRequest):
question = chat_request.body
chat_log = get_or_create_chat_log(chat_id, question)
target_ids = [f"id{id}" for id in chat_request.refer]
# inference_result = inference(question=question, embedding_names=target_ids)
inference_result = "This is model's response"
inference_result = inference(question=question, embedding_names=target_ids)
# inference_result = "This is model's response"
update(chat_log, chat_id, question, inference_result)
return inference_result

0 comments on commit 4bb995c

Please sign in to comment.