mirror of
				https://github.com/anthropics/claude-cookbooks.git
				synced 2025-10-06 01:00:28 +03:00 
			
		
		
		
	WIP Text to SQL - checkpoint
This commit is contained in:
		
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -152,7 +152,4 @@ tests: | ||||
|               "reason": f"SQL {'executed successfully' if execution_success else 'execution failed'}. " | ||||
|                         f"Data {'matches' if data_match else 'does not match'} expected result. " | ||||
|                         f"Actual: {actual_result if row else 'No data'}, Expected: {expected_result}" | ||||
|           } | ||||
|  | ||||
|  | ||||
| outputPath: ../data/results.csv | ||||
|           } | ||||
| @@ -1474,24 +1474,12 @@ | ||||
|     } | ||||
|    ], | ||||
|    "source": [ | ||||
|     "def generate_sql_with_cot(prompt):\n", | ||||
|     "    response = client.messages.create(\n", | ||||
|     "        model=MODEL_NAME,\n", | ||||
|     "        max_tokens=1000,\n", | ||||
|     "        temperature=0,\n", | ||||
|     "        messages=[\n", | ||||
|     "            {\"role\": \"user\", \"content\": prompt}\n", | ||||
|     "        ]\n", | ||||
|     "    )\n", | ||||
|     "    return response.content[0].text.strip()\n", | ||||
|     "\n", | ||||
|     "# Generate SQL using the chain-of-thought prompt\n", | ||||
|     "result = generate_sql_with_cot(prompt)\n", | ||||
|     "result = generate_sql(prompt)\n", | ||||
|     "print(\"Raw response from Claude:\")\n", | ||||
|     "print(result)\n", | ||||
|     "\n", | ||||
|     "# Extract thought process and SQL query using simple string manipulation\n", | ||||
|     "# Note: For more robust parsing, consider using an XML parsing library\n", | ||||
|     "# Extract thought process and SQL query\n", | ||||
|     "thought_process = result.split('<thought_process>')[1].split('</thought_process>')[0].strip()\n", | ||||
|     "sql = result.split('<sql>')[1].split('</sql>')[0].strip()\n", | ||||
|     "\n", | ||||
| @@ -1818,7 +1806,7 @@ | ||||
|     "print(prompt)\n", | ||||
|     "\n", | ||||
|     "# Generate and execute SQL\n", | ||||
|     "result = generate_sql_with_cot(prompt)\n", | ||||
|     "result = generate_sql(prompt)\n", | ||||
|     "print(\"\\nGenerated result:\")\n", | ||||
|     "print(result)\n", | ||||
|     "\n", | ||||
| @@ -2018,7 +2006,7 @@ | ||||
|     "            Explain your changes in <thought_process> tags and provide the corrected SQL in <sql> tags.\n", | ||||
|     "            \"\"\"\n", | ||||
|     "        \n", | ||||
|     "        response = generate_sql_with_cot(prompt)\n", | ||||
|     "        response = generate_sql(prompt)\n", | ||||
|     "        sql = response.split('<sql>')[1].split('</sql>')[0].strip()\n", | ||||
|     "        \n", | ||||
|     "        print(f\"\\nAttempt {attempt + 1}:\")\n", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Mahesh Murag
					Mahesh Murag