---
# System prepended metadata

title: Law ChatGPT

---

# Law ChatGPT

## Question Answering
- spec
```json
POST /v2/case/search
{
    "search_query_id": "<uuid>"  // jurisdictions: "SG" | "UK"
}

response
{
    "search_result_ids": ["<uuid>", "<uuid>"]
    
    // for logging and debug
    "cases": [
        {
            "case_id": "string",
            "title": "string",
            "url": "string",
            "snippet_ids": [
                "<case_id-para_id-para_seq>",
                "<case_id-para_id-para_seq>"
            ],
            "similarity": "number",
            "jurisdictions": ["string"]
        }
    ]
}
```

```json
POST /v2/case/qna
{
    "search_result_ids": ["<uuid>", "<uuid>"]
}

response
{
    "qna_id": "",
    "jurisdictions": string[],
    
    // for debug and logging
    "answer": "markdown_string",
    "no_answer": boolean,
    "citations": [
        {
            "case_id": "",
            "url": "",
            "title": "",
            "citation": "", 
            "snippet": ""
        }
    ]
}
```

```json 
GET /v2/case/search/<search_query_id>/<case_id>
response
{
    "case_id": "string",
    "details": [
        {
            "type":    "area_of_law",
            "content": "string"
        },
        {
            "type":    "issue",
            "content": "string"
        },
        {
            "type":    "rule:proposition",
            "content": "string"
        },
        {
            "type":    "rule:test",
            "content": "string"
        },
        {
            "type":    "rule:element_factor_requirement",
            "content": "string"
        },
        {
            "type":    "rule:definition",
            "content": "string"
        },
        {
            "type":    "summary",
            "content": "string"
        },
        {
            "type":    "legislation_cited",
            "content": "string"
        },
        {
            "type":    "case_cited",
            "content": "string"
        },
        {
            "type":    "paragraph",
            "content": "string",
            "order":   1,
        }, 
        {
            "type":    "paragraph",
            "content": "string",
            "order":   2,
        },
        {
            "type":    "paragraph",
            "content": "string",
            "order":   3
        }
    ]
}
```

```ts
interface Conversation {
    id: string
    messages: Message[]
}

interface Message {
    type: 'query' | 'search_result' | 'qna_result'
    message_id: string
    reference_id: string
}
```

```ts
interface Citation {
    case_id: string
    url: string
    citation: string
}
```

```ts
interface QnAResult {
    qna_id: string
    answer: string
    citations: Citation[]
}
```


```ts
interface SearchResult {
    search_id: string
    cases: Case[]
}
```

```ts
interface Case {
    case_id: string
    title: string
    url: string
    snippet_ids: string[]
    similarity: number
}
```




## Healthz
- spec
```
GET /healthz
{
    "message": "running"
}
```

- sample request
``` bash
curl -XGET 'http://0.0.0.0:5000/healthz'
```

- sample response
```json 
{
    "message": "running"
}
```

# Court Case

## Conversation
- spec

> time format: [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)

```json
POST /case/v1/conversation/:conversation_id
{ 
   "error_type": string | null,
   "error_message": string | null,
   "messages":[
      {
         "message_id":"message_uuid",
         "conversation_id": "conversation_uuid",
         "user_id":"user_uuid",
         "user_role": "user", // "user" "assistant"
         "content":"I want to divorce.",
         "created_at":"2023-01-01T00:00:00Z",
         "meta_data": {
             "jurisdictions": ['SG']
         }
      },
      {
         "conversation_id": "conversation_uuid",
         "message_id": "message_uuid",
         "user_id": "user_uuid",
         "user_role": "assistant",
         "created_at": "2023-01-01",
         "content": "",
         "meta_data": {
             "jurisdictions": ['sg']
         },
         "cases": [
            {
               "case_id": "",
               "title": "",
               "url": "",
               "snippets": [""],
               "meta_data": {
                   "jurisdictions": ['']
               }
            },
            {
               "case_id": "",
               "title": "",
               "url": "",
               "snippets": [""]
            }
         ]
      },
      {
         "message_id":"message_uuid",
         "conversation_id": "conversation_uuid",
         "user_id": "user_uuid",
         "user_role": "user",
         "content":"I want to divorce.",
         "created_at":"2023-01-01"
      }
   ]
}
```

- sample request
```bash
curl -XPOST 'http://0.0.0.0:5000/case/v1/conversation/123' \
     -H 'Content-Type: application/json' \
     -d '{"messages":[{"user_id": "38e0f922-ae87-11ed-b027-acde48001122", "user_role": "user", "message_id": "410368c4-ae87-11ed-b027-acde48001122", "conversation_id": "4501f83c-ae87-11ed-b027-acde48001122", "content": "", "created_at": "2023-01-01T00:00:00Z"}]}'
```

- sample response
```json
{
    "conversation_id": "conversation_id",
    "message_id": "message_uuid", // backend generate uuid for message
    "user_id": "user_uuid",
    "user_role": "assistant",
    "cases": [
        {
            "case_id": "", // backend generate
            "title": "",
            "url": "",
            "snippet": ""
        }
    ]
}
```

## FeedBack

- spec
```json
POST /case/v1/feedback/:conversation_id/:message_id/:case_id
{
    "user_id": string,
    "user_role": "user",
    "feedback": true | false,
    "type": ["irralvent", "low quality"],
    "comment": "the case is not about divorce"
    "messages": []  // for tmp debug and QA
}
```

## Get in Touch
```json
POST /case/v1/get_in_touch/email
{
    "from_email":   "noreply@intelllex.com",
    "from_user":    "Intelllex",
    "to_email":     "contact@intelllex.com",
    "to_user":      "Intelllex",
    "subject":      "Website - Enquiry Form",
    "content":      "# Test title 2\n  - test answer 1\n  - test answer 2\n\n# Test answer\nis\nquite long",
    "content_type": "markdown"
}

curl -XPOST "https://masapi.intelllex.se/get_in_touch/email" -H "Content-type: application/json" -d '{"from_email": "contact@intelllex.com", "to_email": "chlin@intelllex.com", "subject": "test subject", "content": "# Test title 2\n  - test answer 1\n  - test answer 2\n\n# Test answer\nis\nquite long", "content_type": "markdown"}'
```


## Type

```typescript
interface ConversationResponse {
    conversation_id: string // frontend
    messages: Message[]
}

interface Message {
    user_id: string // frontend
    user_role: "user" | "assistant"
    conversation_id: string
    message_id: string // frontend | backend
    message_type: string // search_query | search_result | command | command_result | system_log
    content?: string
    cases?: Case[]
    meta_data?: MessageMetaData
    created_at?: Date
}

type Jurisdiction = 'SG' | 'UK';

interface MessageMetaData {
    jurisdictions?: Jurisdiction[]
}

interface CaseMetaData {
    similarity?: number
}

interface Case {
    case_id: string // backend
    title: string
    url: string
    snippets: string[]
    meta_data?: CaseMetaData
}

interface Feedback {    
    user_id: string
    user_role: "user"
    feedback: boolean
    type?: string[]
    comment?: string
    messages: Message[] 
}
```

## Regenerate (deprecate)

- spec
```
GET /case/v1/regenerate/:conversation_id/:message_id?limit=<number>&page=<number>
```

- sample request
```bash
# curl -XPOST "http://0.0.0.0:5000/case/v1/conversation"
```

- sample response
```json
{
    "conversation_id": "conversation_id",  // for debug
    "message_id": "message_uuid",  // for debug
    "user_id": "user_uuid",
    "user_role": "assistant",
    "cases": [
        {
            "case_id": "",
            "title": "",
            "url": "",
            "snippet": ""
        }
    ]
}
```