{"id":23895054,"url":"https://github.com/kpavlov/ai-mocks","last_synced_at":"2025-04-15T06:52:22.946Z","repository":{"id":274967739,"uuid":"924583734","full_name":"kpavlov/ai-mocks","owner":"kpavlov","description":"Mock Http and LLM servers, inspired by wiremock, but with response streaming and SSE","archived":false,"fork":false,"pushed_at":"2025-04-14T22:35:31.000Z","size":2646,"stargazers_count":12,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T06:52:14.084Z","etag":null,"topics":["kotlin","ktor","ktor-server","langchain4j","llm","mock","mock-server","openai-api"],"latest_commit_sha":null,"homepage":"https://kpavlov.github.io/ai-mocks/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kpavlov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"kpavlov","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":"mailsk","thanks_dev":null,"custom":null}},"created_at":"2025-01-30T09:34:08.000Z","updated_at":"2025-04-14T22:35:33.000Z","dependencies_parsed_at":"2025-01-30T12:58:16.075Z","dependency_job_id":"1a9a1a7f-1c3b-46c4-a11f-070dc0a0f3bd","html_url":"https://github.com/kpavlov/ai-mocks","commit_stats":null,"previous_names":["kpavlov/ai-mocks"],"tags_count":12,"template":false,"template_full_name":"kpavlov/awesome-kotlin-maven-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpavlov%2Fai-mocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpavlov%2Fai-mocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpavlov%2Fai-mocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kpavlov%2Fai-mocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kpavlov","download_url":"https://codeload.github.com/kpavlov/ai-mocks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249023710,"owners_count":21199958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kotlin","ktor","ktor-server","langchain4j","llm","mock","mock-server","openai-api"],"created_at":"2025-01-04T15:50:22.019Z","updated_at":"2025-04-15T06:52:22.940Z","avatar_url":"https://github.com/kpavlov.png","language":"Kotlin","funding_links":["https://github.com/sponsors/kpavlov","https://buymeacoffee.com/mailsk"],"categories":[],"sub_categories":[],"readme":"# Mokksy and AI-Mocks\n\n[![Maven Central](https://img.shields.io/maven-central/v/me.kpavlov.aimocks/ai-mocks-openai)](https://repo1.maven.org/maven2/me/kpavlov/aimocks/ai-mocks-openai/)\n[![Kotlin CI](https://github.com/kpavlov/ai-mocks/actions/workflows/gradle.yml/badge.svg?branch=main)](https://github.com/kpavlov/ai-mocks/actions/workflows/gradle.yml)\n![GitHub branch status](https://img.shields.io/github/checks-status/kpavlov/ai-mocks/main)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/4887b8978534404dbc62c4894b630501)](https://app.codacy.com/gh/kpavlov/ai-mocks/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n[![Codacy Coverage](https://app.codacy.com/project/badge/Coverage/4887b8978534404dbc62c4894b630501)](https://app.codacy.com/gh/kpavlov/ai-mocks/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_coverage)\n[![codecov](https://codecov.io/github/kpavlov/ai-mocks/graph/badge.svg?token=449G80QY5S)](https://codecov.io/github/kpavlov/ai-mocks)\n\n[![Documentation](https://img.shields.io/badge/docs-website-blue)](https://kpavlov.github.io/ai-mocks/) [![API Reference](https://img.shields.io/badge/api-reference-blue)](https://kpavlov.github.io/ai-mocks/api/)\n![GitHub License](https://img.shields.io/github/license/kpavlov/ai-mocks)\n![Kotlin](https://img.shields.io/badge/Kotlin-1.9-%237F52FF.svg?logo=kotlin\u0026logoColor=white)\n\n\n_Mokksy_ and _AI-Mocks_ are mock HTTP and LLM (Large Language Model) servers inspired by WireMock, with support for\nresponse streaming and Server-Side Events (SSE). They are designed to build, test, and mock OpenAI API responses for\ndevelopment purposes.\n\n# Mokksy\n\n![mokksy-mascot-256.png](mokksy/docs/mokksy-mascot-256.png)\n\n**[Mokksy](mokksy/README.md)** is a mock HTTP server built with [Kotlin](https://kotlinlang.org/)\nand [Ktor](https://ktor.io/). It addresses the limitations of WireMock by supporting true SSE and streaming responses,\nmaking it particularly useful for integration testing LLM clients.\n\n## Core Features\n\n- Flexibility to control server response directly via ApplicationCall object.\n- Built with Kotest Assertions.\n- Fluent modern Kotlin DSL API.\n- Support for simulating streamed responses and Server-Side Events (SSE) with delays between chunks.\n- Support for simulating response delays.\n\n## Example Usages\n\n### Responding with Predefined Responses\n\n```kotlin\n// given\nval expectedResponse =\n  // language=json\n  \"\"\"\n    {\n        \"response\": \"Pong\"\n    }\n    \"\"\".trimIndent()\n\nmokksy.get {\n  path = beEqual(\"/ping\")\n  containsHeader(\"Foo\", \"bar\")\n} respondsWith {\n  body = expectedResponse\n}\n\n// when\nval result = client.get(\"/ping\") {\n  headers.append(\"Foo\", \"bar\")\n}\n\n// then\nassertThat(result.status).isEqualTo(HttpStatusCode.OK)\nassertThat(result.bodyAsText()).isEqualTo(expectedResponse)\n```\n\n### POST Request\n\n```kotlin\n// given\nval id = Random.nextInt()\nval expectedResponse =\n  // language=json\n  \"\"\"\n    {\n        \"id\": \"$id\",\n        \"name\": \"thing-$id\"\n    }\n    \"\"\".trimIndent()\n\nmokksy.post {\n  path = beEqual(\"/things\")\n  bodyContains(\"\\\"$id\\\"\")\n} respondsWith {\n  body = expectedResponse\n  httpStatus = HttpStatusCode.Created\n  headers {\n    // type-safe builder style\n    append(HttpHeaders.Location, \"/things/$id\")\n  }\n  headers += \"Foo\" to \"bar\" // list style\n}\n\n// when\nval result =\n  client.post(\"/things\") {\n    headers.append(\"Content-Type\", \"application/json\")\n    setBody(\n      // language=json\n      \"\"\"\n            {\n                \"id\": \"$id\"\n            }\n            \"\"\".trimIndent(),\n    )\n  }\n\n// then\nassertThat(result.status).isEqualTo(HttpStatusCode.Created)\nassertThat(result.bodyAsText()).isEqualTo(expectedResponse)\nassertThat(result.headers[\"Location\"]).isEqualTo(\"/things/$id\")\nassertThat(result.headers[\"Foo\"]).isEqualTo(\"bar\")\n```\n### Server-Side Events (SSE) Response\n\nServer-Side Events (SSE) is a technology that allows a server to push updates to the client over a single, long-lived\nHTTP connection, enabling real-time updates without requiring the client to continuously poll the server for new data.\n\n```kotlin\nmokksy.post {\n  path = beEqual(\"/sse\")\n} respondsWithSseStream {\n  flow =\n    flow {\n      delay(200.milliseconds)\n      emit(\n        ServerSentEvent(\n          data = \"One\",\n        ),\n      )\n      delay(50.milliseconds)\n      emit(\n        ServerSentEvent(\n          data = \"Two\",\n        ),\n      )\n    }\n}\n\n// when\nval result = client.post(\"/sse\")\n\n// then\nassertThat(result.status)\n  .isEqualTo(HttpStatusCode.OK)\nassertThat(result.contentType())\n  .isEqualTo(ContentType.Text.EventStream.withCharsetIfNeeded(Charsets.UTF_8))\nassertThat(result.bodyAsText())\n  .isEqualTo(\"data: One\\r\\ndata: Two\\r\\n\")\n```\n\n# AI-Mocks\n\n**AI-Mocks** is a specialized mock server implementations (e.g., mocking OpenAI API) built using Mokksy.\n\nIt supports mocking following LLMs:\n1. [OpenAI](https://platform.openai.com/docs/api-reference/) - [ai-mocks-openai](https://kpavlov.github.io/ai-mocks/docs/ai-mocks-openai/)\n2. [Anthropic](https://docs.anthropic.com/en/api) - [ai-mocks-anthropic](https://kpavlov.github.io/ai-mocks/docs/ai-mocks-anthropic/)\n\n**_NB! Not all API endpoints and parameters are supported!_**\n\n## How to build\n\nBuilding project locally:\n\n```shell\ngradle build\n```\n\nor using Make:\n\n```shell\nmake\n```\n\n## Contributing\n\nI do welcome contributions! Please see the [Contributing Guidelines](CONTRIBUTING.md) for details.\n\n## Enjoying LLM integration testing? :heart:\n\n[![Buy me a Coffee](https://cdn.buymeacoffee.com/buttons/default-orange.png)](https://buymeacoffee.com/mailsk)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpavlov%2Fai-mocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkpavlov%2Fai-mocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkpavlov%2Fai-mocks/lists"}