Skip to content

Commit

Permalink
#11 Move summary prompt to the server and update the order of the forms
Browse files Browse the repository at this point in the history
  • Loading branch information
sighmon committed May 28, 2024
1 parent 1bef441 commit 1a4daee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
32 changes: 28 additions & 4 deletions api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,30 @@ async def root(

@app.post('/summarise')
async def summarise(request: Request):
"""Returns a summary of the text string."""

"""Returns a summary of the visitor's query vs the results, including an anecdote."""
body = await request.body()
body = body.decode('utf-8')
return llm.invoke(body).content
llm_prompt = f"""
System: You are an ACMI museum guide. Please compare the user's question to the museum
collection items in the response and provide an overall summary of how you think it did
and why as if you were talking to the user in a short one sentence form suitable for
text-to-speech as it will be converted to audio and read back to the visitor.
Apologise if the results don't match, and provide an anecdote about the data
in one of the collection records.
Example: <summary>. <anecdote>
User's query and context:
{body}
"""
return llm.invoke(llm_prompt).content


@app.post('/speak')
async def speak(request: Request):
"""Returns an audio stream of the text string."""
"""Returns an audio stream of the body string."""

text_to_speech = ElevenLabs()
body = await request.body()
Expand All @@ -281,6 +295,16 @@ async def speak(request: Request):
stream=True,
))


@app.post('/similar')
async def similar(request: Request):
"""Returns similar items from the vector database to the body string."""

body = await request.body()
body = body.decode('utf-8')
results = [json_parser.loads(result.page_content) for result in retriever.invoke(body)]
return results

if __name__ == '__main__':
import uvicorn

Expand Down
33 changes: 10 additions & 23 deletions api/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
<h1><a href="/?json=false" title="Take me home">Show me something</a></h1>

<form>
<input type="submit" value="Computer's choice">
<input type="text" name="query" id="query" placeholder="{% if query %}{% else %}Type your own question{% endif %}" value="{% if query %}{{ query }}{% endif %}">
<input type="hidden" name="json" id="json" value="false">
<input type="hidden" name="random" id="random" value="true">
</form>

<ol id="chats">
</ol>
<audio controls>
<source src="{{ url_for('static', path='/audio/seb-are-you-looking-for-something.mp3') }}" type="audio/mp3">
</audio>

<h2>or</h2>

<form onsubmit="mergeSelectionsAndSubmit(event)">
Expand All @@ -35,16 +40,11 @@ <h2>or</h2>
<h2>or</h2>

<form>
<input type="text" name="query" id="query" placeholder="{% if query %}{% else %}Type your own question{% endif %}" value="{% if query %}{{ query }}{% endif %}">
<input type="submit" value="Let me suggest something for you">
<input type="hidden" name="json" id="json" value="false">
<input type="hidden" name="random" id="random" value="true">
</form>

<ol id="chats">
</ol>
<audio controls>
<source src="{{ url_for('static', path='/audio/seb-are-you-looking-for-something.mp3') }}" type="audio/mp3">
</audio>

<ul>
{% for result in results %}
<li>
Expand Down Expand Up @@ -96,25 +96,12 @@ <h3><a href="https://url.acmi.net.au/w/{{ result.id }}" target="_blank">{{ resul
if (!query) {
query = 'Show me a random selection of collection items.';
}
var llm_prompt = `
System: You are an ACMI museum guide. Please compare the user's question to the museum collection items in the response and provide an overall summary of how you think it did and why as if you were talking to the user in a short one sentence form suitable for text-to-speech as it will be converted to audio and read back to the visitor.
Apologise if the results don't match, and provide an anecdote about the data in one of the collection records.
Example: <summary>. <anecdote>
User's question: ${query}
Response:
${results}
`;
fetch('/summarise', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: llm_prompt,
body: `{"query": ${query}, "results": ${results}}`,
})
.then(response => response.json())
.then(data => {
Expand Down

0 comments on commit 1a4daee

Please sign in to comment.