Purumir's Blog

Machine Learning, SW architect, Management, favorites

PROMPTHON EXPERIENCE

Prototype Building with LLMs

Design thinking is a process that follows the steps of Empathize, Define, Ideate, Prototype and Test. In this process, listening to the Voice of the Customer (VoC) is more important than any other step.

For this reason, my team in the prompthon has thought that Large Language Models (LLMs) are effective tools for quickly building prototypes. Traditional coding requires time for developers to construct the logic. However, with prompt engineering, there’s no need to code the logic directly. I simply provided the user’s question, the query based on the user’s question, information about the table and my prompt. Using them, the LLM was able to return the result in an HTML table format.

By integrating the HTML response with a no-code tool component, my team has demonstrated that it’s possible to create prototypes without the time-consuming coding typically required, especially for prototypes that might be discarded later.

langchain + Prompt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from langchain_community.utilities.sql_database import SQLDatabase
from langchain_core.prompts import ChatPromtTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_core.output_parsers import StrOutputParser

promt_query = """
Based on the table schema below,
Write a PostgreSQL query that answer the user's question:
{schema}

Question: {question}
SQL Query:"""

db = SQLDatabase.from_uri("postgresql://~~")

def get_schema(_):
return db.get_table_info()

promt_query = ChatPromptTemplate.form_template(promt_query)
sql_query_chain = (
RunnablePassthrough.assign(schema=get_schema)
| promt_query
| llm.bind(stop=["\nSQLResult:"])
| StrOutputParser()
)
sql_respone = sql_response_chain.invoke({"question": "<USER QUESTION>"})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
prompt_response = """
Based on the table schema, question, sql query and sql response,
write a respone which is the korean language.

Schema : {schema}
Question : {question}
SQL Query : {query}
SQL Response : {response}

If the sql response is not empty, please just follow the below step.
- The test_item, review_criteria, test_method of the sql response must be included in the response.
- When you return the reponse, return the html table code which contains the test_item, review_criteria, test_method.
- And the text of the table header must be written in the korean language.

If the sql response is empty, please just write a below respone.
- "Refer to ~~~"
"""

prompt_response = ChatPromptTemplate.form_template(prompt_response)

full_chain = (
RunnablePassthrough.assign(query=sql_query_chain)
| RunnablePassthrough.assign(
schema=get_schema,
resposne=lanmbda x: db.run(x['query'])
)
| prompt_response
| llm
| StrOutputParser()
)

full_chain.invoke({"question": "<USER QUESTION>"})

Prompt Flow Concept