Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
paulotaylor committed Jul 18, 2023
0 parents commit 6a49cb2
Show file tree
Hide file tree
Showing 15 changed files with 961 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

13 changes: 13 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github: [paulotaylor] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
35 changes: 35 additions & 0 deletions .github/workflows/dokka-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish Dokka Documentation

on:
release:
types: [published]
workflow_dispatch:

jobs:
build-and-publish:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up JDK
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '11'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Generate Dokka HTML documentation
run: ./gradlew dokkaHtml

- name: Deploy to GitHub Pages
uses: JamesIves/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
folder: build/dokka/html
37 changes: 37 additions & 0 deletions .github/workflows/readme-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Update README Version

on:
release:
types:
- published
workflow_dispatch:

jobs:
update-version:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Update version in README
run: |
# Extract the version from the build.gradle.kts file
VERSION=$(grep -oP 'version\s*=\s*"\K\d+\.\d+\.\d+' build.gradle.kts)
# Update the README.md file
export VERSION
python -c "import re, os; version=os.environ['VERSION']; content=open('README.md').read(); content=re.sub(r'\d+\.\d+\.\d+', f'{version}', content); open('README.md', 'w').write(content)"
- name: Commit and push changes
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "[email protected]"
git remote set-url origin https://${{ secrets.PAT }}@github.com/paulotaylor/klaude.git
git add README.md
git diff --quiet && git diff --staged --quiet || (git commit -m "Update version in README.md" && git push)
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Eclipse
.classpath
.project
.settings/

# Intellij
.idea/
*.iml
*.iws

# Mac
.DS_Store

# VSCode
.vscode/

# Netbrans
nbproject/
nbactions.xml

# Gradle
.gradle/
build/
!gradle/wrapper/gradle-wrapper.jar
gradle.properties

# Maven
log/
target/

#
.env
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Paulo Taylor

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<div align="center">

# Klaude - Kotlin Client for Claude from Anthropic
[![Maven Central](https://img.shields.io/maven-central/v/com.klaude/klaude?color=blue&label=Download)](https://central.sonatype.com/namespace/com.klaude)
[![License](https://img.shields.io/github/license/WeaponMechanics/ArmorMechanics)](https://github.com/WeaponMechanics/ArmorMechanics/blob/master/LICENSE)

A community-maintained easy-to-use Java/Kotlin Claude API
</div>

## Documentation
* [Claude API](https://docs.anthropic.com/claude/docs)

## Installation
For Kotlin DSL (`build.gradle.kts`), add this to your dependencies block:
```kotlin
dependencies {
implementation("com.klaude:klaude:0.0.1")
}
```
For Maven projects, add this to your `pom.xml` file in the `<dependencies>` block:
```xml
<dependency>
<groupId>com.klaude</groupId>
<artifactId>klaude</artifactId>
<version>0.0.1</version>
</dependency>
```
See the [maven repository](https://central.sonatype.com/artifact/com.klaude/klaude/0.0.1) for gradle/ant/etc.


## Working Example
This is a basic working example.
```kotlin
fun translateToEnglish() {

val klaudeClient = KlaudeClient.Builder()
.key("YOUR_API_KEY")
.model("claude-2")
.maxTokensToSample(1000)
.build()
val text = "Olá, tudo bem?"
klaudeClient.complete("Translate to English: $text") { result ->
println(result ?: "[empty]")
}
}

fun chat() {
val scan = Scanner(System.`in`)

val klaude = KlaudeClient.Builder()
.model("claude-2")
.key("YOUR_API_KEY")
.maxTokensToSample(500)
.build()

val messages = mutableListOf(KlaudeMessage("You are a helpful assistant", KlaudeMessageType.USER))

println("Start chatting, type 'exit' or 'quit' to finish:\n")

while (true) {

println("Human:")

val input = scan.nextLine().trim()

if (input.isBlank()) {
continue
}

if (input == "exit" || input == "quit") {
break
}
messages.add(KlaudeMessage(input, KlaudeMessageType.USER))

klaude.chat(messages) { reply ->
if (!reply.isNullOrBlank()) {
messages.add(KlaudeMessage(reply.trim(), KlaudeMessageType.ASSISTANT))
println("Assistant:\n${reply.trim()}")
}
}
}
println("DONE")
}

```

## License
Klaude is an open-sourced software licensed under the [MIT License](https://github.com/paulotaylor/klaude/blob/master/LICENSE).
**This is an unofficial library, and is not affiliated with Anthropic**.
Loading

0 comments on commit 6a49cb2

Please sign in to comment.