feat: implementing initial-setup
Browse files- app/config/db.py +2 -2
- app/core/initial_setup/data/initial_chat_completions.json +124 -0
- app/core/initial_setup/setup.py +55 -0
- app/model/chat_model.py +2 -6
- app/repository/chat_repository.py +26 -8
- main.py +6 -0
app/config/db.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from typing import Literal
|
| 2 |
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 3 |
|
| 4 |
|
|
@@ -11,7 +11,7 @@ class DBConfig(BaseSettings):
|
|
| 11 |
)
|
| 12 |
|
| 13 |
|
| 14 |
-
DATABASE_TYPE:
|
| 15 |
DATABASE_NAME: str = "openai_chatbot_api"
|
| 16 |
|
| 17 |
MONGO_USER: str = "root"
|
|
|
|
| 1 |
+
from typing import Literal
|
| 2 |
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 3 |
|
| 4 |
|
|
|
|
| 11 |
)
|
| 12 |
|
| 13 |
|
| 14 |
+
DATABASE_TYPE: Literal["mongodb", "embedded"] = "embedded"
|
| 15 |
DATABASE_NAME: str = "openai_chatbot_api"
|
| 16 |
|
| 17 |
MONGO_USER: str = "root"
|
app/core/initial_setup/data/initial_chat_completions.json
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"chat_completions": [
|
| 3 |
+
{
|
| 4 |
+
"completion_id": "mock-1",
|
| 5 |
+
"title": "Customer count by status",
|
| 6 |
+
"model": "gpt-3.5-turbo",
|
| 7 |
+
"object": "chat.completion",
|
| 8 |
+
"is_archived": false,
|
| 9 |
+
"is_starred": false,
|
| 10 |
+
"created_by": "system",
|
| 11 |
+
"created_date": "2024-03-20T10:00:00Z",
|
| 12 |
+
"last_updated_by": "system",
|
| 13 |
+
"last_updated_date": "2024-03-20T11:00:00Z",
|
| 14 |
+
"messages": [
|
| 15 |
+
{
|
| 16 |
+
"message_id": "mock-1-1",
|
| 17 |
+
"role": "user",
|
| 18 |
+
"content": "count of customers by status",
|
| 19 |
+
"created_date": "2024-03-20T10:01:01Z"
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"message_id": "mock-1-2",
|
| 23 |
+
"role": "assistant",
|
| 24 |
+
"content": "## Result\n|status|count|\n|---|---|\n|active|100|\n|cancelled|30|\n|pending|40|\n|passive|150|\n\n## Explanation\nThis result represents the number of active, cancelled, pending and passive customers in the year 2025. This is a mock result for the question \"How many customers are active, cancelled, pending and passive in the year 2025?\"\n\n## Query\n```sql\nSELECT status, COUNT(*) FROM customers WHERE year = 2025 GROUP BY status;\n```",
|
| 25 |
+
"figure": null,
|
| 26 |
+
"created_date": "2024-03-20T10:02:02Z"
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"message_id": "mock-1-3",
|
| 30 |
+
"role": "user",
|
| 31 |
+
"content": "show me the result in a bar chart",
|
| 32 |
+
"created_date": "2024-03-20T10:03:03Z"
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"message_id": "mock-1-4",
|
| 36 |
+
"role": "assistant",
|
| 37 |
+
"content": "## Result\n|status|count|\n|---|---|\n|active|100|\n|cancelled|30|\n|pending|40|\n|passive|150|\n\n## Explanation\nThis result represents the number of active, cancelled, pending and passive customers in the year 2025. This is a mock result for the question \"How many customers are active, cancelled, pending and passive in the year 2025?\"\n\n## Query\n```sql\nSELECT status, COUNT(*) FROM customers WHERE year = 2025 GROUP BY status;\n```",
|
| 38 |
+
"figure": {"data":[{"alignmentgroup":"True","customdata":[["North"],["North"],["South"]],"hovertemplate":"category=Category A\u003cbr\u003estatus=%{x}\u003cbr\u003ecount=%{y}\u003cbr\u003eregion=%{customdata[0]}\u003cextra\u003e\u003c\u002fextra\u003e","legendgroup":"Category A","marker":{"color":"#636efa","pattern":{"shape":""}},"name":"Category A","offsetgroup":"Category A","orientation":"v","showlegend":true,"textposition":"auto","texttemplate":"%{y}","x":["active","in_review","pending_deletion"],"xaxis":"x","y":{"dtype":"i1","bdata":"Mh4P"},"yaxis":"y","type":"bar"},{"alignmentgroup":"True","customdata":[["South"],["West"]],"hovertemplate":"category=Category B\u003cbr\u003estatus=%{x}\u003cbr\u003ecount=%{y}\u003cbr\u003eregion=%{customdata[0]}\u003cextra\u003e\u003c\u002fextra\u003e","legendgroup":"Category B","marker":{"color":"#EF553B","pattern":{"shape":""}},"name":"Category B","offsetgroup":"Category B","orientation":"v","showlegend":true,"textposition":"auto","texttemplate":"%{y}","x":["passive","newly_added"],"xaxis":"x","y":{"dtype":"i1","bdata":"Rhk="},"yaxis":"y","type":"bar"},{"alignmentgroup":"True","customdata":[["East"]],"hovertemplate":"category=Category C\u003cbr\u003estatus=%{x}\u003cbr\u003ecount=%{y}\u003cbr\u003eregion=%{customdata[0]}\u003cextra\u003e\u003c\u002fextra\u003e","legendgroup":"Category C","marker":{"color":"#00cc96","pattern":{"shape":""}},"name":"Category C","offsetgroup":"Category C","orientation":"v","showlegend":true,"textposition":"auto","texttemplate":"%{y}","x":["archived"],"xaxis":"x","y":{"dtype":"i1","bdata":"Wg=="},"yaxis":"y","type":"bar"}],"layout":{"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"fillpattern":{"fillmode":"overlay","size":10,"solidity":0.2},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#2a3f5f"},"error_y":{"color":"#2a3f5f"},"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"type":"scattergl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermap":[{"type":"scattermap","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"baxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#EBF0F8"},"line":{"color":"white"}},"header":{"fill":{"color":"#C8D4E3"},"line":{"color":"white"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#2a3f5f"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"white","plot_bgcolor":"#E5ECF6","polar":{"bgcolor":"#E5ECF6","angularaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"radialaxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"ternary":{"bgcolor":"#E5ECF6","aaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"baxis":{"gridcolor":"white","linecolor":"white","ticks":""},"caxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"yaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"zaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2}},"shapedefaults":{"line":{"color":"#2a3f5f"}},"annotationdefaults":{"arrowcolor":"#2a3f5f","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"white","landcolor":"#E5ECF6","subunitcolor":"white","showland":true,"showlakes":true,"lakecolor":"white"},"title":{"x":0.05},"mapbox":{"style":"light"}}},"xaxis":{"anchor":"y","domain":[0.0,1.0],"title":{"text":"Status"}},"yaxis":{"anchor":"x","domain":[0.0,1.0],"title":{"text":"Count"}},"legend":{"title":{"text":"Category"},"tracegroupgap":0},"title":{"text":"Bar Chart: Count by Status and Category","x":0.5},"barmode":"group"}},
|
| 39 |
+
"created_date": "2024-03-20T10:04:04Z"
|
| 40 |
+
}
|
| 41 |
+
]
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"completion_id": "mock-2",
|
| 45 |
+
"title": "Ticket count by status",
|
| 46 |
+
"model": "gpt-3.5-turbo",
|
| 47 |
+
"object": "chat.completion",
|
| 48 |
+
"is_archived": false,
|
| 49 |
+
"is_starred": false,
|
| 50 |
+
"created_by": "system",
|
| 51 |
+
"created_date": "2024-03-21T10:00:00Z",
|
| 52 |
+
"last_updated_by": "system",
|
| 53 |
+
"last_updated_date": "2024-03-21T11:00:00Z",
|
| 54 |
+
"messages": [
|
| 55 |
+
{
|
| 56 |
+
"message_id": "mock-2-1",
|
| 57 |
+
"role": "user",
|
| 58 |
+
"content": "count of tickets by status",
|
| 59 |
+
"created_date": "2024-03-20T11:01:01Z"
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"message_id": "mock-2-2",
|
| 63 |
+
"role": "assistant",
|
| 64 |
+
"content": "## Result\n|status|count|\n|---|---|\n|open|100|\n|closed|30|\n|pending|40|\n|reopened|150|\n\n## Explanation\nThis result represents the number of open, closed, pending and reopened tickets in the year 2025. This is a mock result for the question \"How many tickets are open, closed, pending and reopened in the year 2025?\"\n\n## Query\n```sql\nSELECT status, COUNT(*) FROM tickets WHERE year = 2025 GROUP BY status;\n```",
|
| 65 |
+
"figure": null,
|
| 66 |
+
"created_date": "2024-03-20T11:02:02Z"
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"message_id": "mock-2-3",
|
| 70 |
+
"role": "user",
|
| 71 |
+
"content": "show me the result in a pie chart",
|
| 72 |
+
"created_date": "2024-03-20T11:03:03Z"
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"message_id": "mock-2-4",
|
| 76 |
+
"role": "assistant",
|
| 77 |
+
"content": "## Result\n|status|count|\n|---|---|\n|open|100|\n|closed|30|\n|pending|40|\n|reopened|150|\n\n## Explanation\nThis result represents the number of open, closed, pending and reopened tickets in the year 2025. This is a mock result for the question \"How many tickets are open, closed, pending and reopened in the year 2025?\"\n\n## Query\n```sql\nSELECT status, COUNT(*) FROM tickets WHERE year = 2025 GROUP BY status;\n```",
|
| 78 |
+
"figure": {"data":[{"customdata":[[150000,"Dr. Eva Core","High"],[120000,"Mr. Alex Markey","High"],[85000,"Ms. Sarah Ops","Medium"],[45000,"Mr. John Staff","Medium"],[65000,"Ms. Ada Byte","High"],[35000,"Mrs. Jane Doe","Low"]],"domain":{"x":[0.0,1.0],"y":[0.0,1.0]},"hole":0.4,"hovertemplate":"\u003cb\u003e%{hovertext}\u003c\u002fb\u003e\u003cbr\u003e\u003cbr\u003edepartment=%{label}\u003cbr\u003ebudget_allocation_usd=%{customdata[0]:$,.2f}\u003cbr\u003elead_person=%{customdata[1]}\u003cbr\u003epriority_level=%{customdata[2]}\u003cextra\u003e\u003c\u002fextra\u003e","hovertext":["Research & Development","Marketing & Sales","Operations","Human Resources","IT Infrastructure","Administration & Support"],"labels":["Research & Development","Marketing & Sales","Operations","Human Resources","IT Infrastructure","Administration & Support"],"legendgroup":"","name":"","showlegend":true,"values":{"dtype":"i4","bdata":"8EkCAMDUAQAITAEAyK8AAOj9AAC4iAAA"},"type":"pie","marker":{"line":{"color":"#000000","width":1.5}},"textinfo":"percent+label","textposition":"inside"}],"layout":{"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"fillpattern":{"fillmode":"overlay","size":10,"solidity":0.2},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#2a3f5f"},"error_y":{"color":"#2a3f5f"},"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"type":"scattergl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermap":[{"type":"scattermap","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"baxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#EBF0F8"},"line":{"color":"white"}},"header":{"fill":{"color":"#C8D4E3"},"line":{"color":"white"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#2a3f5f"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"white","plot_bgcolor":"#E5ECF6","polar":{"bgcolor":"#E5ECF6","angularaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"radialaxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"ternary":{"bgcolor":"#E5ECF6","aaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"baxis":{"gridcolor":"white","linecolor":"white","ticks":""},"caxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"yaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"zaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2}},"shapedefaults":{"line":{"color":"#2a3f5f"}},"annotationdefaults":{"arrowcolor":"#2a3f5f","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"white","landcolor":"#E5ECF6","subunitcolor":"white","showland":true,"showlakes":true,"lakecolor":"white"},"title":{"x":0.05},"mapbox":{"style":"light"}}},"legend":{"tracegroupgap":0,"title":{"text":"Departments"},"font":{"size":11},"orientation":"v","yanchor":"top","y":0.85,"xanchor":"left","x":1.02,"traceorder":"reversed","bgcolor":"rgba(255,255,255,0.7)","bordercolor":"Gray","borderwidth":1},"title":{"text":"\u003cb\u003eProject Budget Distribution by Department\u003c\u002fb\u003e","font":{"size":22,"family":"Arial Black, sans-serif","color":"#333333"},"y":0.95,"x":0.5,"xanchor":"center","yanchor":"top"},"font":{"family":"Arial, sans-serif","size":12,"color":"#444444"},"paper_bgcolor":"rgb(248, 248, 255)","plot_bgcolor":"rgba(0,0,0,0)","annotations":[{"showarrow":false,"text":"Total Budget\u003cbr\u003e$400,000","x":0.5,"y":0.5,"font":{"size":16,"color":"#1f77b4"}}]}},
|
| 79 |
+
"created_date": "2024-03-20T11:04:04Z"
|
| 80 |
+
}
|
| 81 |
+
]
|
| 82 |
+
},
|
| 83 |
+
{
|
| 84 |
+
"completion_id": "mock-3",
|
| 85 |
+
"title": "Ticket comments count by customer status",
|
| 86 |
+
"model": "gpt-3.5-turbo",
|
| 87 |
+
"object": "chat.completion",
|
| 88 |
+
"is_archived": false,
|
| 89 |
+
"is_starred": false,
|
| 90 |
+
"created_by": "system",
|
| 91 |
+
"created_date": "2024-03-22T10:00:00Z",
|
| 92 |
+
"last_updated_by": "system",
|
| 93 |
+
"last_updated_date": "2024-03-22T11:00:00Z",
|
| 94 |
+
"messages": [
|
| 95 |
+
{
|
| 96 |
+
"message_id": "mock-3-1",
|
| 97 |
+
"role": "user",
|
| 98 |
+
"content": "count of ticket comments by status",
|
| 99 |
+
"created_date": "2024-03-22T11:01:01Z"
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"message_id": "mock-3-2",
|
| 103 |
+
"role": "assistant",
|
| 104 |
+
"content": "## Result\n|status|count|\n|---|---|\n|open|100|\n|closed|30|\n|pending|40|\n|reopened|150|\n\n## Explanation\nThis result represents the number of open, closed, pending and reopened tickets in the year 2025. This is a mock result for the question \"How many tickets are open, closed, pending and reopened in the year 2025?\"\n\n## Query\n```sql\nSELECT status, COUNT(*) FROM tickets WHERE year = 2025 GROUP BY status;\n```",
|
| 105 |
+
"figure": null,
|
| 106 |
+
"created_date": "2024-03-22T11:02:02Z"
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
"message_id": "mock-3-3",
|
| 110 |
+
"role": "user",
|
| 111 |
+
"content": "show me the result in a line chart",
|
| 112 |
+
"created_date": "2024-03-22T11:03:03Z"
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
"message_id": "mock-3-4",
|
| 116 |
+
"role": "assistant",
|
| 117 |
+
"content": "## Result\n|status|count|\n|---|---|\n|open|100|\n|closed|30|\n|pending|40|\n|reopened|150|\n\n## Explanation\nThis result represents the number of open, closed, pending and reopened tickets in the year 2025. This is a mock result for the question \"How many tickets are open, closed, pending and reopened in the year 2025?\"\n\n## Query\n```sql\nSELECT status, COUNT(*) FROM tickets WHERE year = 2025 GROUP BY status;\n```",
|
| 118 |
+
"figure": {"data":[{"customdata":[["math"],["math"],["science"],["science"],["art"],["art"],["science"],["science"],["math"]],"hovertemplate":"status=active\u003cbr\u003edate=%{x}\u003cbr\u003ecount=%{y}\u003cbr\u003esubject=%{customdata[0]}\u003cextra\u003e\u003c\u002fextra\u003e","legendgroup":"active","line":{"color":"#3498db","dash":"solid"},"marker":{"symbol":"circle"},"mode":"lines+markers","name":"active","orientation":"v","showlegend":true,"x":["2025-01-01T00:00:00.000000000","2025-02-01T00:00:00.000000000","2025-03-01T00:00:00.000000000","2025-04-01T00:00:00.000000000","2025-05-01T00:00:00.000000000","2025-06-01T00:00:00.000000000","2025-07-01T00:00:00.000000000","2025-08-01T00:00:00.000000000","2025-09-01T00:00:00.000000000"],"xaxis":"x","y":{"dtype":"i1","bdata":"Cg8MEg4UEBYZ"},"yaxis":"y","type":"scatter"},{"customdata":[["math"],["math"],["science"],["science"],["math"],["math"],["music"],["music"],["history"]],"hovertemplate":"status=archived\u003cbr\u003edate=%{x}\u003cbr\u003ecount=%{y}\u003cbr\u003esubject=%{customdata[0]}\u003cextra\u003e\u003c\u002fextra\u003e","legendgroup":"archived","line":{"color":"#9b59b6","dash":"solid"},"marker":{"symbol":"circle"},"mode":"lines+markers","name":"archived","orientation":"v","showlegend":true,"x":["2025-01-01T00:00:00.000000000","2025-02-01T00:00:00.000000000","2025-03-01T00:00:00.000000000","2025-04-01T00:00:00.000000000","2025-05-01T00:00:00.000000000","2025-06-01T00:00:00.000000000","2025-07-01T00:00:00.000000000","2025-08-01T00:00:00.000000000","2025-09-01T00:00:00.000000000"],"xaxis":"x","y":{"dtype":"i1","bdata":"KC0qMCwyLzc8"},"yaxis":"y","type":"scatter"},{"customdata":[["english"],["english"],["math"],["math"],["history"],["history"],["art"],["art"],["english"]],"hovertemplate":"status=in_review\u003cbr\u003edate=%{x}\u003cbr\u003ecount=%{y}\u003cbr\u003esubject=%{customdata[0]}\u003cextra\u003e\u003c\u002fextra\u003e","legendgroup":"in_review","line":{"color":"#2ecc71","dash":"solid"},"marker":{"symbol":"circle"},"mode":"lines+markers","name":"in_review","orientation":"v","showlegend":true,"x":["2025-01-01T00:00:00.000000000","2025-02-01T00:00:00.000000000","2025-03-01T00:00:00.000000000","2025-04-01T00:00:00.000000000","2025-05-01T00:00:00.000000000","2025-06-01T00:00:00.000000000","2025-07-01T00:00:00.000000000","2025-08-01T00:00:00.000000000","2025-09-01T00:00:00.000000000"],"xaxis":"x","y":{"dtype":"i1","bdata":"HiMgJh4kIScq"},"yaxis":"y","type":"scatter"},{"customdata":[["science"],["science"],["english"],["english"],["music"],["music"],["english"],["english"],["science"]],"hovertemplate":"status=passive\u003cbr\u003edate=%{x}\u003cbr\u003ecount=%{y}\u003cbr\u003esubject=%{customdata[0]}\u003cextra\u003e\u003c\u002fextra\u003e","legendgroup":"passive","line":{"color":"#e74c3c","dash":"solid"},"marker":{"symbol":"circle"},"mode":"lines+markers","name":"passive","orientation":"v","showlegend":true,"x":["2025-01-01T00:00:00.000000000","2025-02-01T00:00:00.000000000","2025-03-01T00:00:00.000000000","2025-04-01T00:00:00.000000000","2025-05-01T00:00:00.000000000","2025-06-01T00:00:00.000000000","2025-07-01T00:00:00.000000000","2025-08-01T00:00:00.000000000","2025-09-01T00:00:00.000000000"],"xaxis":"x","y":{"dtype":"i1","bdata":"FBkWHBQaEhgP"},"yaxis":"y","type":"scatter"}],"layout":{"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"fillpattern":{"fillmode":"overlay","size":10,"solidity":0.2},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#2a3f5f"},"error_y":{"color":"#2a3f5f"},"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"type":"scattergl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermap":[{"type":"scattermap","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"baxis":{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","minorgridcolor":"white","startlinecolor":"#2a3f5f"},"type":"carpet"}],"table":[{"cells":{"fill":{"color":"#EBF0F8"},"line":{"color":"white"}},"header":{"fill":{"color":"#C8D4E3"},"line":{"color":"white"}},"type":"table"}],"barpolar":[{"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"pie":[{"automargin":true,"type":"pie"}]},"layout":{"autotypenumbers":"strict","colorway":["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692","#B6E880","#FF97FF","#FECB52"],"font":{"color":"#2a3f5f"},"hovermode":"closest","hoverlabel":{"align":"left"},"paper_bgcolor":"white","plot_bgcolor":"#E5ECF6","polar":{"bgcolor":"#E5ECF6","angularaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"radialaxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"ternary":{"bgcolor":"#E5ECF6","aaxis":{"gridcolor":"white","linecolor":"white","ticks":""},"baxis":{"gridcolor":"white","linecolor":"white","ticks":""},"caxis":{"gridcolor":"white","linecolor":"white","ticks":""}},"coloraxis":{"colorbar":{"outlinewidth":0,"ticks":""}},"colorscale":{"sequential":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"sequentialminus":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]],"diverging":[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]]},"xaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"yaxis":{"gridcolor":"white","linecolor":"white","ticks":"","title":{"standoff":15},"zerolinecolor":"white","automargin":true,"zerolinewidth":2},"scene":{"xaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"yaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2},"zaxis":{"backgroundcolor":"#E5ECF6","gridcolor":"white","linecolor":"white","showbackground":true,"ticks":"","zerolinecolor":"white","gridwidth":2}},"shapedefaults":{"line":{"color":"#2a3f5f"}},"annotationdefaults":{"arrowcolor":"#2a3f5f","arrowhead":0,"arrowwidth":1},"geo":{"bgcolor":"white","landcolor":"#E5ECF6","subunitcolor":"white","showland":true,"showlakes":true,"lakecolor":"white"},"title":{"x":0.05},"mapbox":{"style":"light"}}},"xaxis":{"anchor":"y","domain":[0.0,1.0],"title":{"text":"Date"},"showgrid":true,"gridcolor":"#e0e0e0","zeroline":false,"tickformat":"%Y-%m-%d"},"yaxis":{"anchor":"x","domain":[0.0,1.0],"title":{"text":"Count"},"showgrid":true,"gridcolor":"#e0e0e0","zeroline":false},"legend":{"title":{"text":"Status"},"tracegroupgap":0,"orientation":"h","yanchor":"bottom","y":1.02,"xanchor":"right","x":1},"title":{"text":"Line Chart of Count Over Time by Status","font":{"size":20,"family":"Arial","color":"#2c3e50"},"y":0.95,"x":0.5,"xanchor":"center","yanchor":"top"},"font":{"family":"Arial","size":12,"color":"#333"},"plot_bgcolor":"#f5f6f5","paper_bgcolor":"#ffffff","showlegend":true}},
|
| 119 |
+
"created_date": "2024-03-22T11:04:04Z"
|
| 120 |
+
}
|
| 121 |
+
]
|
| 122 |
+
}
|
| 123 |
+
]
|
| 124 |
+
}
|
app/core/initial_setup/setup.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
from typing import List, Optional
|
| 4 |
+
from loguru import logger
|
| 5 |
+
from app.model.chat_model import ChatCompletion
|
| 6 |
+
from app.repository.chat_repository import ChatRepository
|
| 7 |
+
from app.config.db import db_config
|
| 8 |
+
|
| 9 |
+
class InitialSetup:
|
| 10 |
+
"""Initial setup manager for the application"""
|
| 11 |
+
|
| 12 |
+
def __init__(self):
|
| 13 |
+
self._chat_repository: Optional[ChatRepository] = None
|
| 14 |
+
self.data_dir = os.path.join(os.path.dirname(__file__), "data")
|
| 15 |
+
|
| 16 |
+
@property
|
| 17 |
+
def chat_repository(self) -> ChatRepository:
|
| 18 |
+
"""Lazy loading of ChatRepository"""
|
| 19 |
+
if self._chat_repository is None:
|
| 20 |
+
self._chat_repository = ChatRepository()
|
| 21 |
+
return self._chat_repository
|
| 22 |
+
|
| 23 |
+
def _load_initial_data(self) -> List[ChatCompletion]:
|
| 24 |
+
"""Load initial data from JSON files"""
|
| 25 |
+
try:
|
| 26 |
+
with open(os.path.join(self.data_dir, "initial_chat_completions.json"), "r") as f:
|
| 27 |
+
data = json.load(f)
|
| 28 |
+
return [ChatCompletion(**item) for item in data["chat_completions"]]
|
| 29 |
+
except Exception as e:
|
| 30 |
+
logger.error(f"Error loading initial data: {e}")
|
| 31 |
+
return []
|
| 32 |
+
|
| 33 |
+
async def setup(self) -> None:
|
| 34 |
+
"""Setup initial data if database type is embedded"""
|
| 35 |
+
if db_config.DATABASE_TYPE != "embedded":
|
| 36 |
+
logger.info("Skipping initial setup as database type is not embedded")
|
| 37 |
+
return
|
| 38 |
+
|
| 39 |
+
logger.info("Starting initial setup for embedded database")
|
| 40 |
+
|
| 41 |
+
# Load and save initial chat completions
|
| 42 |
+
chat_completions = self._load_initial_data()
|
| 43 |
+
for completion in chat_completions:
|
| 44 |
+
try:
|
| 45 |
+
self.chat_repository.save(completion)
|
| 46 |
+
logger.info(f"Saved initial chat completion: {completion.completion_id}")
|
| 47 |
+
except Exception as e:
|
| 48 |
+
logger.error(f"Error saving chat completion {completion.completion_id}: {e}")
|
| 49 |
+
|
| 50 |
+
# query of the saved chat completions
|
| 51 |
+
saved_chat_completions = self.chat_repository.find()
|
| 52 |
+
logger.info(f"Saved chat completions: {saved_chat_completions}")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
logger.info("Initial setup completed successfully")
|
app/model/chat_model.py
CHANGED
|
@@ -5,7 +5,7 @@ from enum import Enum
|
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from datetime import datetime
|
| 7 |
from pydantic import Field
|
| 8 |
-
from typing import List
|
| 9 |
|
| 10 |
# Chat completion payload example
|
| 11 |
# {
|
|
@@ -90,11 +90,7 @@ class ChatCompletion(BaseModel):
|
|
| 90 |
A chat completion.
|
| 91 |
"""
|
| 92 |
|
| 93 |
-
completion_id: str = Field(
|
| 94 |
-
...,
|
| 95 |
-
description="The unique identifier for the chat completion",
|
| 96 |
-
default_factory=lambda: str(uuid.uuid4()),
|
| 97 |
-
)
|
| 98 |
|
| 99 |
# openai compatible fields
|
| 100 |
model: str = Field(
|
|
|
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from datetime import datetime
|
| 7 |
from pydantic import Field
|
| 8 |
+
from typing import List, Optional
|
| 9 |
|
| 10 |
# Chat completion payload example
|
| 11 |
# {
|
|
|
|
| 90 |
A chat completion.
|
| 91 |
"""
|
| 92 |
|
| 93 |
+
completion_id: Optional[str] = Field(None, description="The unique identifier for the chat completion")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
# openai compatible fields
|
| 96 |
model: str = Field(
|
app/repository/chat_repository.py
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
from typing import List
|
| 2 |
from app.db.factory import db_client
|
| 3 |
from app.model.chat_model import ChatMessage, ChatCompletion
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
class ChatRepository:
|
| 7 |
def __init__(self):
|
|
|
|
| 8 |
self.db = db_client.db
|
| 9 |
self.collection = "chat_completion"
|
| 10 |
|
|
@@ -12,38 +15,53 @@ class ChatRepository:
|
|
| 12 |
"""
|
| 13 |
Upsert a chat completion into the database. If the chat completion already exists, it will be updated. If it does not exist, it will be created.
|
| 14 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
query = {"completion_id": entity.completion_id}
|
| 16 |
update = {"$set": entity.model_dump()}
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
completion_id =
|
| 21 |
entity.completion_id = completion_id
|
| 22 |
|
| 23 |
# save conversation if new chat completion
|
| 24 |
# TODO: save conversation
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
def find(self, query: dict, page: int = 1, limit: int = 10, sort: dict =
|
| 29 |
"""
|
| 30 |
Find a chat completion by a given query. with pagination
|
| 31 |
Example : query = {"created_by": "admin"}
|
| 32 |
"""
|
| 33 |
-
|
| 34 |
skip = (page - 1) * limit
|
| 35 |
sort = sort if sort else {"created_date": -1}
|
| 36 |
|
| 37 |
result = self.db.chat_completion.find(query, project).skip(skip).limit(limit).sort(sort)
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
def find_by_id(self, completion_id: str, project: dict = None) -> ChatCompletion:
|
| 41 |
"""
|
| 42 |
Find a chat completion by a given id.
|
| 43 |
Example : completion_id = "123"
|
| 44 |
"""
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def find_messages(self, completion_id: str) -> List[ChatMessage]:
|
| 49 |
"""
|
|
|
|
| 1 |
from typing import List
|
| 2 |
from app.db.factory import db_client
|
| 3 |
from app.model.chat_model import ChatMessage, ChatCompletion
|
| 4 |
+
from loguru import logger
|
| 5 |
+
import uuid
|
| 6 |
|
| 7 |
|
| 8 |
class ChatRepository:
|
| 9 |
def __init__(self):
|
| 10 |
+
logger.info("Initializing ChatRepository")
|
| 11 |
self.db = db_client.db
|
| 12 |
self.collection = "chat_completion"
|
| 13 |
|
|
|
|
| 15 |
"""
|
| 16 |
Upsert a chat completion into the database. If the chat completion already exists, it will be updated. If it does not exist, it will be created.
|
| 17 |
"""
|
| 18 |
+
logger.debug(f"BEGIN: save chat completion. input data: {entity.model_dump()}")
|
| 19 |
+
if entity.completion_id is None:
|
| 20 |
+
logger.warning("completion_id is None. Generating a new one")
|
| 21 |
+
else:
|
| 22 |
+
logger.debug(f"completion_id is not None. Using the existing one: {entity.completion_id}")
|
| 23 |
+
|
| 24 |
query = {"completion_id": entity.completion_id}
|
| 25 |
update = {"$set": entity.model_dump()}
|
| 26 |
|
| 27 |
+
upserted_entity = self.db.chat_completion.update_one(query, update, upsert=True)
|
| 28 |
+
logger.debug(f"upserted_entity: {upserted_entity}")
|
| 29 |
|
| 30 |
+
completion_id = entity.completion_id if entity.completion_id else str(uuid.uuid4())
|
| 31 |
entity.completion_id = completion_id
|
| 32 |
|
| 33 |
# save conversation if new chat completion
|
| 34 |
# TODO: save conversation
|
| 35 |
|
| 36 |
+
result = self.find_by_id(completion_id)
|
| 37 |
+
logger.debug("END: save chat completion")
|
| 38 |
+
return result
|
| 39 |
|
| 40 |
+
def find(self, query: dict = {}, page: int = 1, limit: int = 10, sort: dict = {"created_date": -1}, project: dict = None) -> List[ChatCompletion]:
|
| 41 |
"""
|
| 42 |
Find a chat completion by a given query. with pagination
|
| 43 |
Example : query = {"created_by": "admin"}
|
| 44 |
"""
|
| 45 |
+
logger.debug(f"BEGIN: find chat completion. input parameters: query: {query}, page: {page}, limit: {limit}, sort: {sort}, project: {project}")
|
| 46 |
skip = (page - 1) * limit
|
| 47 |
sort = sort if sort else {"created_date": -1}
|
| 48 |
|
| 49 |
result = self.db.chat_completion.find(query, project).skip(skip).limit(limit).sort(sort)
|
| 50 |
+
logger.debug(f"result: {result}")
|
| 51 |
+
result = [ChatCompletion(**item) for item in result]
|
| 52 |
+
logger.debug("END: find chat completion")
|
| 53 |
+
return result
|
| 54 |
|
| 55 |
def find_by_id(self, completion_id: str, project: dict = None) -> ChatCompletion:
|
| 56 |
"""
|
| 57 |
Find a chat completion by a given id.
|
| 58 |
Example : completion_id = "123"
|
| 59 |
"""
|
| 60 |
+
logger.debug(f"BEGIN: find chat completion by id. input parameters: completion_id: {completion_id}, project: {project}")
|
| 61 |
+
entity = self.db.chat_completion.find_one({"completion_id": completion_id}, project)
|
| 62 |
+
result = ChatCompletion(**entity)
|
| 63 |
+
logger.debug("END: find chat completion by id")
|
| 64 |
+
return result
|
| 65 |
|
| 66 |
def find_messages(self, completion_id: str) -> List[ChatMessage]:
|
| 67 |
"""
|
main.py
CHANGED
|
@@ -12,6 +12,7 @@ from app.db.factory import db_client
|
|
| 12 |
from gradio_chatbot import build_gradio_app, app_auth
|
| 13 |
import gradio as gr
|
| 14 |
import os
|
|
|
|
| 15 |
|
| 16 |
print(log_config.get_log_level())
|
| 17 |
|
|
@@ -34,6 +35,11 @@ async def lifespan(app: FastAPI):
|
|
| 34 |
# Startup
|
| 35 |
logger.info("Starting up application...")
|
| 36 |
await db_client.connect()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
yield
|
| 38 |
|
| 39 |
# Shutdown
|
|
|
|
| 12 |
from gradio_chatbot import build_gradio_app, app_auth
|
| 13 |
import gradio as gr
|
| 14 |
import os
|
| 15 |
+
from app.core.initial_setup.setup import InitialSetup
|
| 16 |
|
| 17 |
print(log_config.get_log_level())
|
| 18 |
|
|
|
|
| 35 |
# Startup
|
| 36 |
logger.info("Starting up application...")
|
| 37 |
await db_client.connect()
|
| 38 |
+
|
| 39 |
+
# Run initial setup if database type is embedded
|
| 40 |
+
initial_setup = InitialSetup()
|
| 41 |
+
await initial_setup.setup()
|
| 42 |
+
|
| 43 |
yield
|
| 44 |
|
| 45 |
# Shutdown
|